Java List Compare compareLists(List a, List b)

Here you can find the source of compareLists(List a, List b)

Description

compare two lists

License

Open Source License

Parameter

Parameter Description
a a parameter
b a parameter

Return

the comparison result

Declaration

public static int compareLists(List<String> a, List<String> b) 

Method Source Code

//package com.java2s;

import java.util.List;

public class Main {
    /**/*from  w w w  .  j  av a2  s  . c o m*/
     * compare two lists
     * @param a
     * @param b
     * @return the comparison result
     */
    public static int compareLists(List<String> a, List<String> b) {
        if (a == b)
            return 0;
        if (a != null && b == null)
            return -1;
        if (a == null && b != null)
            return 1;
        if (a.size() != b.size())
            return -1;

        for (int i = 0; i < a.size(); i++) {
            final String aval = a.get(i);
            final String bval = b.get(i);

            if (aval == null && bval == null)
                continue;
            if (aval == null && bval != null)
                return 1;
            if (aval != null && bval == null)
                return -1;

            final int c = aval.compareTo(bval);
            if (c != 0)
                return c;
        }

        return 0;
    }
}

Related

  1. compareLists(Class type, List list1, List list2)
  2. compareLists(final List list1, final List list2)
  3. compareLists(List strings1, List strings2, boolean ignoreCase)
  4. compareLists(List l1, List l2)
  5. compareLists(List list, List> listOfLists)
  6. compareLists(List a, List b)
  7. compareLists(List list1, List list2)
  8. compareLists(Object obj1, Object obj2)
  9. compareLists(String list1[], String list2[])