1 /* 2 * This program will process the ArrayList 3 */ 4 5 6 package arraylistplay; 7 8 import java.util.ArrayList; 9 10 public class Primes { 11 public static void main(String[]args){ 12 ArrayList<Integer>primes= new ArrayList<>(); 13 14 primes.add(2); 15 primes.add(3); 16 primes.add(5); 17 primes.add(7); 18 19 System.out.println("size of primes list="+primes.size()); 20 System.out.println("first primes="+ primes.get(0)); 21 System.out.println("last prime="+ primes.get(3)); 22 System.out.println("last prime=" +primes.get(primes.size()-1)); 23 24 25 26 System.out.println("\nThe initial list..."); 27 for (Integer prime: primes){ 28 System.out.println(prime); 29 } 30 int temp= primes.get(0); 31 primes.set(0, primes.get(primes.size()-1));// this sets up the last element to be in the first list 32 primes.set(primes.size()-1, temp);// this brings the last element to the temp to print as prime(0) 33 34 System.out.println("\nThe final list...."); 35 for (Integer prime: primes){ 36 System.out.println(prime); 37 } 38 39 40 } 41 } 42 43 44