发布网友 发布时间:2022-04-22 21:47
共1个回答
热心网友 时间:2022-04-17 20:38
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;
}