Java合并两个数组,把相同的数据都去掉(不是去重!不是去重!不是去重!)? 50
2020-04-12
public static void main(String[] args) {
int[] arr = new int[]{1,2,3,4};
int[] arr1 = new int[]{3,4,5,6};
List<Integer> list = combineArray(arr, arr1);
int size = list.size();
int[] arrNew = new int[size];
for (int i =0; i < size; i ++) {
arrNew[i] = list.get(i);
}
for (int i =0; i < size; i ++) {
System.out.println(arrNew[i]);
}
}
public static List<Integer> combineArray(int[] arr, int[] arr1) {
List<Integer> list = Arrays.stream(arr).boxed().collect(Collectors.toList());
List<Integer> list1 = Arrays.stream(arr1).boxed().collect(Collectors.toList());
List<Integer> listAll = new ArrayList<>();
listAll.addAll(list);
listAll.addAll(list1);
list1.retainAll(list);
listAll.removeAll(list1);
return listAll;
}