// File: TestGeneric2.java // // Author: Rahul Simha // Created: Sept 2008 // // Illustrates Java generics using the Java API. // Need this for java.util.ArrayList. import java.util.*; public class TestGeneric2 { public static void main (String[] argv) { // This is a data-structure in the Java library: ArrayList L = new ArrayList (); // Add stuff the list was originally designed for: L.add (new Integer(5)); L.add (new Integer(6)); L.add (new Integer(7)); L.add (new Integer(8)); // New for loop: for (Integer I: L) { System.out.println (I); } // An interesting variant that uses autoboxing: for (int i: L) { System.out.println (i); } } }