ArrayList import java.util.ArrayList; public class Example { public static void main(String[] args){ ArrayList results = new ArrayList<>(); // variable results refers to an object, // so list can be manipulated through it results.add(2.5); results.add(5.75); results.add(4.5); for (double result : results) { System.out.println(result); } } } Program outputs: 2.5 5.75 4.5 ================================ Several references to the same object import java.util.ArrayList; public class Example { public static void main(String[] args){ ArrayList numbers = new ArrayList<>(); ArrayList numbersTwo = numbers; // refer to the same 'numbers' list numbers.add(5); numbers.add(9); numbers.add(15); numbersTwo.add(17); numbersTwo.add(21); System.out.println(numbers); System.out.println(numbersTwo); } } Program outputs: [5, 9, 15, 17, 21] [5, 9, 15, 17, 21] ================================ Easy to match same content for BASIC TYPEs Scanner reader = new Scanner(System.in); while (true) { System.out.print("Give a number: "); int num = Integer.valueOf(reader.nextLine()); if (num == 10) { System.out.println("You gave a ten!"); break; } } Example execution: Give a number: 5 Give a number: 6 Give a number: 3 Give a number: 10 You gave a ten! VS Difficult to match same object for REFERENCE/OBJECT TYPEs - match references - not matching content ArrayList list1 = new ArrayList<>(); ArrayList list2 = new ArrayList<>(); ArrayList list3 = list1; list1.add(1); list1.add(2); list1.add(3); list2.add(1); list2.add(2); list2.add(3); System.out.println("list1 == list2? " + (list1 == list2)); System.out.println("list1 == list3? " + (list1 == list3)); System.out.println("list2 == list3? " + (list2 == list3)); Program outputs: list1 == list2? false // DIFFERENT REFERENCE BUT SAME CONTENT list1 == list3? true // SAME REFERENCE, cuz list3 was refererring to list1, and its contents list2 == list3? false // DIFFERENT REFERENCE BUT SAME CONTENT ================================ The 'equals' operator can be used to compare the SIMILARITY of OBJECTS. The operator returns true if the objects have the SAME CONTENT. ArrayList list1 = new ArrayList<>(); ArrayList list2 = new ArrayList<>(); ArrayList list3 = list1; list1.add(1); list1.add(2); list1.add(3); list2.add(1); list2.add(2); list2.add(3); System.out.println("list1.equals(list2) " + (list1.equals(list2))); System.out.println("list1.equals(list3) " + (list1.equals(list3))); System.out.println("list2.equals(list3) " + (list2.equals(list3))); Program outputs: list1.equals(list2) true list1.equals(list3) true list2.equals(list3) true ================================ Since STRINGS are Java OBJECTS, their EQUALITY must also be compared using the EQUALS operator, for example Scanner reader = new Scanner(System.in); System.out.print("Give a name: "); String name = reader.nextLine(); if (name == "Jack Java") { System.out.println("nimi == Jack Java"); // THIS DID NOT RUN } if (name.equals("Jack Java")){ System.out.println("the name is Jack Java"); // THIS RAN } Program outputs: Give a name: Jack Java the name is Jack Java