假如 a[1,2,3,4,5], b[1,2,3,4] 怎么取得两个数组中不相同的部分 就如怎么取得 5
public static <T> List<T> compare(T[] t1, T[] t2) {
List<T> list1 = Arrays.asList(t1);
List<T> list2 = new ArrayList<T>();
for (T t : t2) {
if (!list1.contains(t)) {
list2.add(t);
}
}
return list2;
}
compare(new Integer[] { 1, 2, 3 }, new Integer[] {
1, 2, 3, 4 })
public static <T> List<T> compare(T[] t1, T[] t2) { List<T> list1 = Arrays.asList(t1); List<T> list2 = new ArrayList<T>(); for (T t : t2) { if (!list1.contains(t)) { list2.add(t); } } return list2; } compare(new Integer[] { 1, 2, 3 }, new Integer[] { 1, 2, 3, 4 })