1. How to compare equals for two List:
? ? 1> Writing boiler plate code
? ? 2> Using org.apache.commons.collections.ListUtils.isEqualList()
class="java" name="code">public static boolean isEqualList(final Collection list1, final Collection list2) {
if (list1 == list2) {
return true;
}
if (list1 == null || list2 == null || list1.size() != list2.size()) {
return false;
}
Iterator it1 = list1.iterator();
Iterator it2 = list2.iterator();
Object obj1 = null;
Object obj2 = null;
while (it1.hasNext() && it2.hasNext()) {
obj1 = it1.next();
obj2 = it2.next();
if (!(obj1 == null ? obj2 == null : obj1.equals(obj2))) {
return false;
}
}
return !(it1.hasNext() || it2.hasNext());
}
?
2. How to compare equals for two Set:
? ? 1> Using org.apache.commons.collections.SetUtils.isEqualSet()
?