Streets.java
1    /* 
2     * create a program using arraylists that mimic the array program for streets and also work 
3     * similarly by analogy through the primes arraylist 
4     */
5    
6    package arraylistplay;
7    
8    import java.util.ArrayList;
9    
10   public class Streets {
11   //create an array list with the names of the streets in new orleans
12       public static void main(String[] args){
13           ArrayList<String> streets = new ArrayList<>();
14           streets.add("Iberville");
15           streets.add("Decatur");
16           streets.add("Toulouse");
17           streets.add("Boubon");
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           //print the size of the array list, print the 1 element, the last element, and the last elment again using the
27           //list arrays length
28           System.out.println("The size of the streets list = " + streets.size());
29           System.out.println("The first street in the list = " + streets.get(0));
30           System.out.println("The last street in the list = " + streets.get(11));
31           System.out.println("The last street in the list...again... = " + streets.get(streets.size()-1));
32           //print the names within the array list
33           System.out.println("\nThe initial list ...");
34           //for each loop makes a variable equal the first element, and then cycles through the list
35           for (String street : streets){
36               System.out.println(street);
37           }
38           //switch the first and last elements and then print the list again.
39           String temp = streets.get(0);
40           streets.set(0, streets.get(streets.size()-1));
41           streets.set(streets.size()-1, temp);
42   
43           System.out.println("\nThe final list ...");
44           for (String street : streets){
45               System.out.println(street);
46           }
47   
48       }
49   }
50