这是一个简单的方法,可以检查2个数组列表是否包含相同的值,而不管它们的顺序如何。
//the name of the method explains it well... public boolean isTwoArrayListsWithSamevalues(ArrayList<Object> list1, ArrayList<Object> list2) { //null checking if(list1==null && list2==null) return true; if((list1 == null && list2 != null) || (list1 != null && list2 == null)) return false; if(list1.size()!=list2.size()) return false; for(Object itemList1: list1) { if(!list2.contains(itemList1)) return false; } return true; }


