Created
January 12, 2020 22:07
-
-
Save jvoytech/a4b8ba7664474ffc860a6752382c09bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class TestListPop { | |
private final List<String> states = new ArrayList<>(); | |
public void push(String state) { | |
states.add(state); | |
} | |
public String pop() { | |
int lastIndex = states.size() - 1; | |
String lastState = states.get(lastIndex); | |
states.remove(lastState); | |
return lastState; | |
} | |
public String pop_nobug() { | |
return states.remove(states.size() - 1); | |
} | |
@Override | |
public String toString() { | |
return "TestList{" + "states=" + String.join("-", states) + '}'; | |
} | |
public static void main(String[] args) { | |
test1(); | |
test2(); | |
} | |
public static void test1() { | |
System.out.println("--== Test1 ==--"); | |
TestListPop testList = new TestListPop(); | |
testList.push("a"); | |
testList.push("a"); | |
testList.push("b"); | |
testList.push("a"); | |
System.out.println("before pop: testList = " + testList); | |
testList.pop(); | |
System.out.println("after pop: testList = " + testList); | |
} | |
public static void test2() { | |
System.out.println("--== Test2 ==--"); | |
TestListPop testList = new TestListPop(); | |
testList.push("a"); | |
testList.push("a"); | |
testList.push("b"); | |
testList.push("a"); | |
System.out.println("before pop: testList = " + testList); | |
testList.pop_nobug(); | |
System.out.println("after pop: testList = " + testList); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment