| 93 | } |
| 94 | // There are some things that only LinkedLists can do: |
| 95 | public static void testLinkedList() { |
| 96 | LinkedList<String> ll = new LinkedList<>(); |
| 97 | ll.addAll(LIST); |
| 98 | System.out.println(ll); |
| 99 | // Treat it like a stack, pushing: |
| 100 | ll.addFirst("one"); |
| 101 | ll.addFirst("two"); |
| 102 | System.out.println(ll); |
| 103 | // Like "peeking" at the top of a stack: |
| 104 | System.out.println(ll.getFirst()); |
| 105 | // Like popping a stack: |
| 106 | System.out.println(ll.removeFirst()); |
| 107 | System.out.println(ll.removeFirst()); |
| 108 | // Treat it like a queue, pulling elements |
| 109 | // off the tail end: |
| 110 | System.out.println(ll.removeLast()); |
| 111 | System.out.println(ll); |
| 112 | } |
| 113 | public static void main(String[] args) { |
| 114 | // Make and fill a new list each time: |
| 115 | basicTest(new LinkedList<>(LIST)); |