import java.util.*; class UseArrayLists1 // Demonstrates changing all occurrences of an integer in an // ArrayList of integers to another integer destructively, // showing difference between aliasing and copying. // Includes method to create new unset ArrayList of given length // and static method to copy. { public static void main(String[] args) throws Exception { Scanner input = new Scanner(System.in); System.out.println("Enter some numbers (all on one line, separated by spaces):"); String line = input.nextLine(); String[] numbers = line.split(" "); ArrayList a = makeArrayListInt(numbers.length); for(int i=0; i b=a; ArrayList c=copy(a); System.out.println("\nThe ArrayList is "+a); System.out.println("The ArrayList viewed through its alias is "+b); System.out.println("The copy of the ArrayList is "+c); System.out.print("\nEnter two numbers: "); int p = input.nextInt(), q=input.nextInt(); System.out.println("Change "+p+" to "+q+" in the ArrayList"); change(a,p,q); System.out.println("\nThe ArrayList is now "+a); System.out.println("The ArrayList viewed through its alias is now "+b); System.out.println("The copy of the ArrayList is now "+c); } private static ArrayList makeArrayListInt(int n) { ArrayList a = new ArrayList(); for(int i=0; i copy(ArrayList a) { ArrayList b = makeArrayListInt(a.size()); for(int i=0; i a,int m,int n) // Change all occurrences of m to n in a destructively { for(int i=0; i