我一直试图解决这个问题几天但是不能这样做。在本练习中,两个ArrayLists
有一个整数列表。必须删除每个列表中包含的整数,并且应该在一个ArrayList
中显示不相同的数字(假设arrayList1
与arrayList2
合并)。我只想使用foreach
循环。主要没有变化。仅在方法中请求更改。
public class SmartCombining {
public static void smartCombine(ArrayList<Integer> list1, ArrayList<Integer> list2) {
int index = 0;
int index2 = 0;
for (int number : list1) {
for (int num2 : list2) {
if (list2.contains(number) == list1.contains(num2)) {
list2.remove(index2);
list1.remove(index);
}
index2++;
}
index++;
}
list1.addAll(list2);
}
public static void main(String[] args) {
ArrayList<Integer> list1 = new ArrayList<Integer>();
ArrayList<Integer> list2 = new ArrayList<Integer>();
Collections.addAll(list1, 4, 3);
Collections.addAll(list2, 5, 10, 4, 3, 7);
// Remove comment when method ready
// smartCombine(list1, list2);
System.out.println(list1);
System.out.println(list2);
}
}
答案 0 :(得分:0)
您可以保持firebase.database().ref().child("usersProfile").orderByChild("name").on("value", function(snapshot) {
callback(snapshot);
});
不受影响,只需删除list1
常用的元素,然后添加list2
但不在{{1}中的元素,即可修改list1
}}。在退出list1
方法之前,您可以将list2
添加到smartCombine
以获取列表之间的并集,list2
将包含对称差异,即不包含两者的元素列表。
list1
答案 1 :(得分:0)
function saveclick()
{
window.alert('Check the users before saving');
}