June 2018
Beginner
722 pages
18h 47m
English
Every Java collection implements the equals() method, which compares it with another collection. In the case of List, two lists are considered equal (the method list1.equals(list2) returns true) when:
Here is the code that illustrates it:
List<String> list1 = new ArrayList<>();list1.add("s1");list1.add("s2");List<String> list2 = new ArrayList<>();list2.add("s1");list2.add("s2");System.out.println(list1.equals(list2)); //prints: truelist2.sort(Comparator.reverseOrder());System.out.println(list2); //prints: [s2, s1]System.out.println(list1.equals(list2)); //prints: false
If two lists are equal, ...
Read now
Unlock full access