我对Java真的很陌生。我需要知道两个数组之间的新项目和以前的项目。例子:
A1= {4,5,6};
A2={5,6,7};
result: new item is 7
former item is 4.
我尝试这段代码没有结果:
import java.util.Arrays;
import java.util.List;
Integer[] s1 = {4, 5, 6};
Integer[] s2 = {5,6,7};
List<Integer> s1List = new ArrayList(Arrays.asList(s1));
for (Integer s : s2) {
if (s1List.contains(s)) {
s1List.remove(s);
}
else {
s1List.add(s);
}
System.out.println("nouveaux items =" + s1List);
}
我怎样才能做到这一点 ?