I want to compare two ArrayList of string arrays.
List<String[]> list1 = new ArrayList<String[]>;
List<String[]> list2 = new ArrayList<String[]>;
list1.equals(list2);
This will return false because equals method in ArrayList will do equals on the element.
ListIterator<E> e1 = listIterator();
ListIterator<?> e2 = ((List<?>) o).listIterator();
while (e1.hasNext() && e2.hasNext()) {
E o1 = e1.next();
Object o2 = e2.next();
if (!(o1==null ? o2==null : o1.equals(o2)))
return false;
}
return !(e1.hasNext() || e2.hasNext());
If you do equals on array, it will check reference equality. Is there anyway we can use list1.equals(list2) instead of checking each element in array list.
ListIterator<E[]>, then useArrays.equalsinstead ofo1.equals(o2))Arrays.equalsthat's in theArraysclass.