Junior — Senior
Behavior of the equals() method when comparing ArrayList and LinkedList
livecode
Task condition
The task considers two lists – one implemented as ArrayList, the other as LinkedList. Two identical string elements "Jonh" are added to each of them. It is required to understand what result will be output when comparing these lists using the equals() method.
List<String> arr = new ArrayList<>();
List<String> lin = new LinkedList<>();
arr.add("Jonh");
arr.add("Jonh");
lin.add("Jonh");
lin.add("Jonh");
System.out.println(arr.equals(lin));
Note that the equals method for collections compares not the types of lists, but their contents and the order of elements.