176k views
0 votes
What is the output of the following code? import java.util\.\*; public class Test { public static void main(String[] args) { List list1 = new ArrayList<>(); list1.add("Atlanta"); list1.add("Macon"); list1.add("Savanna"); List list2 = new ArrayList<>(); list2.add("Atlanta"); list2.add("Macon"); list2.add("Savanna"); List list3 = new ArrayList<>(); list3.add("Macon"); list3.add("Savanna"); list3.add("Atlanta"); System.out.println(list1.equals(list2) + " " + list1.equals(list3)); } }

1 Answer

6 votes

Answer:

true false

Step-by-step explanation:

list1 is assigned as Atlanta, Macon, Savanna

list2 is assigned as Atlanta, Macon, Savanna

list3 is assigned as Macon, Atlanta, Savanna

After these assignments,

The program checks if lis1 is equal to list2 and prints the result. Since both lists are equal, it will print true

The program checks if lis1 is equal to list3 and prints the result. Even though both lists contain the same elements, the order is different, it will print false.

User Amina
by
4.4k points