Here you can find the source of compareLists(String list1[], String list2[])
Parameter | Description |
---|---|
list1 | a parameter |
list2 | a parameter |
public static boolean compareLists(String list1[], String list2[])
//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; } }