Java Utililty Methods List Compare

List of utility methods to do List Compare

Description

The list of methods to do List Compare are organized into topic(s).

Method

intcompareLists(List list1, List list2)
Provides a consistent ordering over lists.
if (list1 == null && list2 == null)
    return 0;
if (list1 == null || list2 == null) {
    throw new IllegalArgumentException();
int size1 = list1.size();
int size2 = list2.size();
int size = Math.min(size1, size2);
...
booleancompareLists(Object obj1, Object obj2)
compare Lists
if (null == obj1 && null == obj2) {
    return true;
} else if (null != obj1 && null != obj2) {
    if (obj1 instanceof List && obj2 instanceof List) {
        if (((List) obj1).size() != ((List) obj2).size()) {
            return false;
        } else {
            Set set = new HashSet();
...
booleancompareLists(String list1[], String list2[])
Compares two lists of strings
if (null == list1 || null == list2) {
    return false;
int size = list1.length;
if (size != list2.length) {
    return false;
java.util.Arrays.sort(list1);
...
booleancompareListsAndNull(List arg1, List arg2)
compare Lists And Null
if (arg1 == null && arg2 == null) {
    return true;
} else if ((arg1 == null && arg2 != null) || (arg1 != null && arg2 == null) || arg1.size() != arg2.size()) {
    return false;
} else {
    for (int i = 0; i < arg1.size(); i++) {
        if (!compareObjectsAndNull(arg1.get(i), arg2.get(i))) {
            return false;
...
booleancomparer(Comparator comparator, T object, T... withList)
comparer
return Arrays.stream(withList).noneMatch(with -> comparator.compare(object, with) != 0);
booleancompareStringList(List list1, List list2)
Compare the given lists of strings.
if (list1.size() == list2.size()) {
    ArrayList<String> l1 = new ArrayList<String>(list1);
    ArrayList<String> l2 = new ArrayList<String>(list2);
    Comparator<String> c = new Comparator<String>() {
        public int compare(String o1, String o2) {
            return o1.compareToIgnoreCase(o2);
    };
...
booleancompareStringLists(List elements1, List elements2)
Compare two array lists, if any of the elements in elements1 matches to either one of the element in elements2, return true else return false.
for (String element1 : elements1) {
    for (String element2 : elements2) {
        if (element1.equals(element2)) {
            return true;
return false;
...
booleancompareSubstring(List pieces, String s)
compare Substring
boolean result = true;
int len = pieces.size();
if (len == 1) {
    return s.equals(pieces.get(0));
int index = 0;
loop: for (int i = 0; i < len; i++) {
    String piece = pieces.get(i);
...
intcompareTermList(final List tl0, final List tl1)
Compare two term lists by comparing their subterms in order.
int minSize = Math.min(tl0.size(), tl1.size());
int compare = 0;
for (int i = 0; (compare == 0) && (i < minSize); ++i) {
    compare = tl0.get(i).compareTo(tl1.get(i));
if (compare == 0) {
    compare = tl1.size() - tl0.size();
if (compare < 0) {
    return -1;
} else if (compare > 0) {
    return 1;
} else {
    return 0;
intcompareTo(List list, int i, int j)
compare To
return list.get(i).compareTo(list.get(j));