|
@@ -2,7 +2,6 @@ package com.ym.mec.util.collection;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.ListIterator;
|
|
|
|
|
|
public class ListUtil {
|
|
|
|
|
@@ -13,35 +12,35 @@ public class ListUtil {
|
|
|
* @return
|
|
|
*/
|
|
|
public static boolean isEquals(List<?> list1, List<?> list2) {
|
|
|
- if (null != list1 && null != list2) {
|
|
|
- if(list1.size() != list2.size()){
|
|
|
- return false;
|
|
|
- }
|
|
|
- ListIterator<?> listIterator = list1.listIterator();
|
|
|
- while(listIterator.hasNext()){
|
|
|
- Object obj = listIterator.next();
|
|
|
- if(!list2.contains(obj)){
|
|
|
- return false;
|
|
|
- }
|
|
|
- listIterator.remove();
|
|
|
- list2.remove(obj);
|
|
|
- }
|
|
|
+ if (list1 == list2) {
|
|
|
+ return true;
|
|
|
}
|
|
|
- return true;
|
|
|
+ if (list1 == null && list2 == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (list1 == null || list2 == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (list1.size() != list2.size()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (list1.containsAll(list2) && list2.containsAll(list1)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
List<Integer> list1 = new ArrayList<Integer>();
|
|
|
list1.add(2);
|
|
|
- list1.add(2);
|
|
|
list1.add(1);
|
|
|
-
|
|
|
+ list1.add(1);
|
|
|
+
|
|
|
List<Integer> list2 = new ArrayList<Integer>();
|
|
|
+ list2.add(1);
|
|
|
list2.add(2);
|
|
|
- list2.add(2);
|
|
|
- list2.add(2);
|
|
|
-
|
|
|
- System.out.println(isEquals(list1,list2)? "true" : "false");
|
|
|
+ list2.add(1);
|
|
|
+
|
|
|
+ System.out.println(isEquals(list1, list2) ? "true" : "false");
|
|
|
}
|
|
|
}
|