// There are some things that only LinkedLists can do: 只有linkedLists可以做的 public static void testLinkedList() { LinkedList ll = new LinkedList(); Collection1.fill(ll, 5); print(ll); // Treat it like a stack, pushing: ll.addFirst("one"); ll.addFirst("two"); print(ll); // Like "peeking" at the top of a stack: System.out.println(ll.getFirst()); // Like popping a stack: System.out.println(ll.removeFirst()); System.out.println(ll.removeFirst()); // Treat it like a queue, pulling elements off the tail end: System.out.println(ll.removeLast()); // With the above operations, it's a dequeue! print(ll); }
// Producing a Collection of the values: public static void printValues(Map m) { System.out.print("Values: "); Collection1.print(m.values()); }
// Producing a Set of the keys: public static void printKeys(Map m) { System.out.print("Size = " + m.size() + ", "); System.out.print("keys: "); Collection1.print(m.keySet()); }
// Wrap Collection1.fill() for convenience: public static List fill(List a) { return (List) Collection1.fill(a); }