1 /* 2 * ArrayList with a String. 3 */ 4 5 package arraylistplay; 6 import java.util.ArrayList; 7 8 public class Streets { 9 10 public static void main(String[] args) { 11 12 ArrayList<String> streets = new ArrayList<>(); 13 14 streets.add("Iberville"); 15 streets.add("Decatur"); 16 streets.add("Toulouse"); 17 streets.add("Bourbon"); 18 streets.add("Dauphine"); 19 streets.add("Royal"); 20 streets.add("St Ann"); 21 streets.add("St Peter"); 22 streets.add("Conti"); 23 streets.add("Exchange"); 24 streets.add("Bienville"); 25 streets.add("Dumaine"); 26 27 System.out.println("size of street list = " + streets.size()); 28 System.out.println("first street = " + streets.get(0)); 29 System.out.println("last street = " + streets.get(11)); 30 System.out.println("last street = " + streets.get(streets.size()-1)); 31 32 System.out.println("\nThe initial list..."); 33 for ( String street : streets ) { 34 System.out.println(street); 35 } 36 37 String temp = streets.get(0); 38 streets.set(0, streets.get(streets.size()-1)); 39 streets.set(streets.size()-1,temp); 40 41 System.out.println("\nThe final list..."); 42 for ( String street : streets ) { 43 System.out.println(street); 44 } 45 } 46 } 47