为了账号安全,请及时绑定邮箱和手机立即绑定

请各位大佬指点!JAVA中的集合如何遍历?

请各位大佬指点!JAVA中的集合如何遍历?

月关宝盒 2019-06-10 09:36:03
比如有5个list:listA={a,b,c}listB={d,e,f}listc={x,y,z,k,l}listc={1,2}listc={8,9,0,5}要将几个list的内容进行组合,结果为{adx18},{bey29},{efz0},{k5},{l}依次类推,实际情况可能会有更多的list,list里元素也会更多
查看完整描述

2 回答

?
拉风的咖菲猫

TA贡献1995条经验 获得超2个赞

packagecom.ui;
importjava.util.ArrayList;
importjava.util.Arrays;
importjava.util.List;
publicclassIter{
publicstaticintgetMaxSize(List>list){
if(null==list||list.size()<=0){
return0;
}
intmax=0;
for(Listcur:list){
if(cur.size()>max){
max=cur.size();
}
}
returnmax;
}
publicstaticvoidmain(String[]args){
Lista=newArrayList(Arrays.asList(newString[]{"a","b","c"}));
Listb=newArrayList(Arrays.asList(newString[]{"d","e","f"}));
Listc=newArrayList(Arrays.asList(newString[]{"x","y","z","k","l"}));
Listd=newArrayList(Arrays.asList(newString[]{"1","2"}));
Liste=newArrayList(Arrays.asList(newString[]{"8","9","0","5"}));
List>groupList=newArrayList>();
groupList.add(a);
groupList.add(b);
groupList.add(c);
groupList.add(d);
groupList.add(e);
intindex=getMaxSize(groupList);
for(inti=0;iStringBuilderbuilder=newStringBuilder();
for(Listgroup:groupList){
if(group.size()>i){
builder.append(group.get(i));
}
}
System.out.println(builder.toString());
}
}
}
                            
查看完整回答
反对 回复 2019-06-10
  • 2 回答
  • 0 关注
  • 133 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信