定义两个List集合,把两个List内容合并放到第三个List

版权声明:如需转载,请务必通知! https://blog.csdn.net/qq_39594542/article/details/85111773

这是自定义的list ,你们可以用jdk中的list,都一个意思
MyArrayList list1 = new MyArrayList();
show1 s =new show1();
s.setId(1);
s.setSoftware(“iphone”);
show1 s1 =new show1();
s1.setId(2);
s1.setSoftware(“ipad”);
show1 s2 =new show1();
s2.setId(3);
s2.setSoftware(“thinkpad”);
list1.add(s);
list1.add(s1);
list1.add(s2);
MyArrayList list2 = new MyArrayList();
show2 sh2 = new show2();
sh2.setId(1);
sh2.setSoftware(“手机”);
show2 sh3 = new show2();
sh3.setId(2);
sh3.setSoftware(“平板电脑”);
show2 sh4 = new show2();
sh4.setId(3);
sh4.setSoftware(“笔记本电脑”);
list2.add(sh2);
list2.add(sh3);
list2.add(sh4);
MyArrayList list3 = new MyArrayList();
int a = 1 ;
for(int i = 0;i<list2.size();i++){
show2 sm2 = list2.get(i);
System.out.println(sm2.getId()+"—"+sm2.getSoftware());
for(int j = 0; j<list1.size();j++){
show1 sm= list1.get(j);
if(sm.getId()==sm2.getId()){
list3.add(new show3(a,sm.getSoftware(),sm2.getSoftware()));
a++;
}
System.out.println(sm.getId()+"+++++"+sm.getSoftware());
}
}
for(int l = 0; l<list3.size();l++){
show3 sm3 = list3.get(l);
System.out.println(sm3.getId()+","+sm3.getSoftware()+","+sm3.getSoftwarename());
}

猜你喜欢

转载自blog.csdn.net/qq_39594542/article/details/85111773
今日推荐