展开全部
public static void main(String[] args) {
int[] arr = new int[]{1,2,3,4};
int[] arr1 = new int[]{3,4,5,6};
List 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 combineArray(int[] arr, int[] arr1) {
List list = Arrays.stream(arr).boxed().collect(Collectors.toList());
List list1 = Arrays.stream(arr1).boxed().collect(Collectors.toList());
List listAll = new ArrayList<>();
listAll.addAll(list);
listAll.addAll(list1);
list1.retainAll(list);
listAll.removeAll(list1);
return listAll;
}