Java List Compare compareLists(String list1[], String list2[])

Here you can find the source of compareLists(String list1[], String list2[])

Description

Compares two lists of strings

License

Open Source License

Parameter

Parameter Description
list1 a parameter
list2 a parameter

Return

Returns true if two arrays of strings contain the same strings. Returns false if either list is null.

Declaration

public static boolean compareLists(String list1[], String list2[]) 

Method Source Code

//package com.java2s;
/* Copyright (C) 2008 SRI International
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *//* w w  w  . j  a va2 s  .  co  m*/

public class Main {
    /**
     * Compares two lists of strings
     * @param list1
     * @param list2
     * @return  Returns true if two arrays of strings contain the same strings.  Returns false if either list is null.
     */
    public static boolean compareLists(String list1[], String list2[]) {
        if (null == list1 || null == list2) {
            return false;
        }
        int size = list1.length;
        if (size != list2.length) {
            return false;
        }

        java.util.Arrays.sort(list1);
        java.util.Arrays.sort(list2);
        boolean found = false;
        for (int i = 0; i < size; i++) {
            found = false;
            for (int j = 0; j < size; j++) {
                if (0 == list1[i].compareTo(list2[j])) {
                    found = true;
                    break;
                }
            }
            if (false == found) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. compareLists(List list, List> listOfLists)
  2. compareLists(List a, List b)
  3. compareLists(List a, List b)
  4. compareLists(List list1, List list2)
  5. compareLists(Object obj1, Object obj2)
  6. compareListsAndNull(List arg1, List arg2)
  7. comparer(Comparator comparator, T object, T... withList)
  8. compareStringList(List list1, List list2)
  9. compareStringLists(List elements1, List elements2)