1 package arraylistplay; 2 3 import java.util.ArrayList; 4 5 //This is similar to the Primes program but seems to use an ArrayList. 6 public class Primes2 { 7 public static void main(String[] args) { 8 //Creating the ArrayList. 9 ArrayList<Integer> primes = new ArrayList<>(); 10 primes.add(2); 11 primes.add(3); 12 primes.add(5); 13 primes.add(7); 14 //Outputting info from the ArrayList. 15 System.out.println("size of primes list = " + primes.size()); 16 System.out.println("first prime = " + primes.get(0)); 17 System.out.println("last prime = " + primes.get(3)); 18 System.out.println("last prime = " + primes.get(primes.size()-1)); 19 //Establishing a for loop. 20 System.out.println("\nThe initial list = " + primes.size()); 21 for (Integer prime : primes) {//I'm curious what this command does, and why it does it. 22 System.out.println(prime); //seems to output primes list 23 } 24 //I'll detail each 25 int temp = primes.get(0); //setting temp to primes.get(o) which is 2 26 primes.set(0, primes.get(primes.size()-1)); //this looks like it will get 0 - end 27 primes.set(primes.size()-1,temp); //this looks like it starts at end and ends with 0 (beginning) 28 //I'll probably detail the same way. 29 System.out.println("\nThe final list ..."); 30 //another for statement here... 31 for (Integer prime : primes) { //seems to output the primes information 32 System.out.println(prime); //still don't completely understand primes : primes 33 }//this one seems to use the earlier information which altered the primes list to go backwards. 34 35 } 36 } 37