| 16 | private static Iterator<String> it; |
| 17 | private static ListIterator<String> lit; |
| 18 | public static void basicTest(List<String> a) { |
| 19 | a.add(1, "x"); // Add at location 1 |
| 20 | a.add("x"); // Add at end |
| 21 | // Add a collection: |
| 22 | a.addAll(LIST); |
| 23 | // Add a collection starting at location 3: |
| 24 | a.addAll(3, LIST); |
| 25 | b = a.contains("1"); // Is it in there? |
| 26 | // Is the entire collection in there? |
| 27 | b = a.containsAll(LIST); |
| 28 | // Lists allow random access, which is cheap |
| 29 | // for ArrayList, expensive for LinkedList: |
| 30 | s = a.get(1); // Get (typed) object at location 1 |
| 31 | i = a.indexOf("1"); // Tell index of object |
| 32 | b = a.isEmpty(); // Any elements inside? |
| 33 | it = a.iterator(); // Ordinary Iterator |
| 34 | lit = a.listIterator(); // ListIterator |
| 35 | lit = a.listIterator(3); // Start at location 3 |
| 36 | i = a.lastIndexOf("1"); // Last match |
| 37 | a.remove(1); // Remove location 1 |
| 38 | a.remove("3"); // Remove this object |
| 39 | a.set(1, "y"); // Set location 1 to "y" |
| 40 | // Keep everything that's in the argument |
| 41 | // (the intersection of the two sets): |
| 42 | a.retainAll(LIST); |
| 43 | // Remove everything that's in the argument: |
| 44 | a.removeAll(LIST); |
| 45 | i = a.size(); // How big is it? |
| 46 | a.clear(); // Remove all elements |
| 47 | } |
| 48 | public static void iterMotion(List<String> a) { |
| 49 | ListIterator<String> it = a.listIterator(); |
| 50 | b = it.hasNext(); |