import java.util.ArrayList; /** * This is an example of a generic list. It is really just a wrapper to * Java's ArrayList. I am using it as a short demo of generic classes. * * @author Stephanie Taylor */ public class MyList { private ArrayList list; /** Constructor. * Make an empty list */ public MyList() { list = new ArrayList(); } /** Add an element * * @param e, the element to add */ public void add( Elem e ) { this.list.add( e ); } /** Return a String representation of the list * * @return a String representation of the list */ public String toString() { String ret = "[ "; for (int i = 0; i < this.list.size(); i++ ) ret += list.get(i) + " "; ret += "]"; return ret; } /** Test the add and toString methods */ public static void main( String[] args ) { MyList intList = new MyList(); intList.add( 5 ); intList.add( 2 ); System.out.println( intList ); } }