Java List Compare compare(List strList1, List strList2)

Here you can find the source of compare(List strList1, List strList2)

Description

Compare this two list whether equal

License

Open Source License

Parameter

Parameter Description
strList1 List<String>
strList2 List<String>

Return

boolean

Declaration

@Deprecated
public static boolean compare(List<String> strList1, List<String> strList2) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**//from   w  w w .  jav a  2 s . c  om
     * 
     * Compare this two list whether equal
     * 
     * @param strList1 List<String>
     * @param strList2 List<String>
     * @return boolean
     */
    @Deprecated
    public static boolean compare(List<String> strList1, List<String> strList2) {
        List<String> list1 = strList1 == null ? new ArrayList<String>() : strList1;
        List<String> list2 = strList2 == null ? new ArrayList<String>() : strList2;

        if (list1.size() != list2.size()) {
            return false;
        }
        for (String str1 : list1) {
            boolean isFound = false;
            int index = 0;
            for (String str2 : list2) {
                if (str1.equals(str2)) {
                    isFound = true;
                    break;
                }
                index++;
            }
            if (isFound) {
                list2.remove(index);
            } else {
                return false;
            }
        }

        if (list2.isEmpty()) {
            return true;
        }
        return false;
    }

    /**
     * return true value whether string is empty.
     * 
     * @param string String The source string
     * @return boolean
     */
    public static boolean isEmpty(String string) {

        return string == null || string.trim().length() == 0;

    }

    public static String trim(String string) {
        if (string == null) {
            return null;
        }

        return string.trim();
    }
}

Related

  1. canonicalCompare(List o1, List o2, Comparator elemComparator)
  2. compare(List lhs, Collection rhs, List standard)
  3. compare(List> beanList1, List> beanList2, final int[] sortKeys, final boolean[] sortAscending, final boolean nullAlwaysFirst, final int naOrder)
  4. compare(List list1, List list2)
  5. compare(List a, List b)
  6. compare(List a, List b)
  7. compare(String str, List list)
  8. compareByList(List list, T a, T b)
  9. compareFileLists(List expected, List gotten)