import java.lang.*; import java.util.Iterator; import java.util.List; import java.util.ArrayList; /** * Sample for List. */ class ListSample { /** * Do it. */ public void doIt() { List list = new ArrayList(); // add to list. list.add("apple"); list.add("orange"); list.add("peach"); // get values. for (int i = 0; i < list.size(); i++) { String value = (String)list.get(i); System.out.println("list.get(\"" + i + "\") = " + value); } // List to Iterator. Iterator iterator = list.iterator(); while (iterator.hasNext()) { String value = (String)iterator.next(); System.out.println(value); } } public static void main(String args[]) { ListSample sample = new ListSample(); sample.doIt(); } }