//找出arrayList2中有的arrayList1里边没有的
int[] arrayList1 = new int[]{1,2,3};
int[] arrayList2 = new int[]{2,3,4};
List<Integer> arrayList3 = new ArrayList<Integer>();
List<Integer> arrayList4 = new ArrayList<Integer>();
//用arrayList2 匹配arrayList21
for (int num:arrayList2) {
if (Arrays.binarySearch(arrayList1, num)>=0){
// 相同的数据
arrayList3.add(num);
}else{
// 不同的数据
arrayList4.add(num);
}
}
return arrayList4;
输出结果
4
//找出arrayList1中有的arrayList2里边没有的 int[] arrayList1 = new int[]{1,2,3}; int[] arrayList2 = new int[]{2,3,4}; List<Integer> arrayList3 = new ArrayList<Integer>(); List<Integer> arrayList4 = new ArrayList<Integer>(); //用arrayList1 匹配arrayList2 for (int num:arrayList1) { if (Arrays.binarySearch(arrayList2, num)<=0){ // 相同的数据 arrayList3.add(num); }else{ // 不同的数据 arrayList4.add(num); } }输出结果
1