/********************************************************************** * Author: Eric Heim * Date Created: 7/14/2011 * Course: CS0007 * Description: Shows the use of the set, remove, and add methods for * the ArrayList class **********************************************************************/ import java.util.ArrayList; public class ArrayListInsertRemoveReplace { public static void main(String[] args) { ArrayList nameList = new ArrayList(); nameList.add("Eric"); nameList.add("Thomas"); nameList.add("Steve"); printArrayList(nameList); System.out.println("Adding Joe to index 1"); nameList.add(1, "Joe"); printArrayList(nameList); System.out.println("Removing the name at index 0"); nameList.remove(0); printArrayList(nameList); System.out.println("Replacing the name at index 2 with Jack"); nameList.set(2, "Jack"); printArrayList(nameList); } public static void printArrayList(ArrayList theList) { for(int i = 0; i < theList.size(); i++) { System.out.println("Index:\t" + i + " Name:\t" + theList.get(i)); } } }