ArrayListTest4 - aList.remove(2); aList.set(1,...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.ArrayList; import java.util.Iterator; i public class ArrayListTest4 { public static void main (String [] arg) { System.out.println("\nArrayListTest \n"); ArrayList<String> aList = new ArrayList<String>(); aList.add("Mary"); aList.add("James"); aList.add("Kevin"); System.out.println("aList contains:"); Iterator it = aList.iterator(); while (it.hasNext()) { System.out.println(; } aList.add(1, "Tanya"); String temp = aList.get(3); System.out.println("temp is" + temp);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: aList.remove(2); aList.set(1, "John"); System.out.println("size of aList is " + aList.size()); System.out.println("\n aList now contains:"); it = aList.iterator(); while (it.hasNext()) { System.out.println(; } //using the toString method in the ArrayList<String> class System.out.println("\n aList using toString:"); System.out.println(aList);//why?? because String has a toString method } }...
View Full Document

This note was uploaded on 06/07/2010 for the course CS 201 taught by Professor Staff during the Spring '08 term at Iona.

Ask a homework question - tutors are online