// Helene Martin, CSE 143 // Demonstrates polymorphism through interfaces: the addAndPrint method will // work for any object type that implements the IntList interface! // New version adds a List interface and generics. public class ListClient { public static void main(String[] args) { List list1 = new ArrayList(); addAndPrint(list1); List list2 = new LinkedList(); addAndPrint(list2); List tas = new ArrayList(); tas.add("Melissa"); tas.add("Dane"); tas.add("Chris"); } // Calls several methods on an ArayIntList. // pre: list is not null public static void addAndPrint(List list) { list.add(34); list.add(17); list.add(23); list.add(1, 6); list.set(1, -17); System.out.println(list); list.remove(0); for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } } }