比如有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());}}}
添加回答
举报
0/150
提交
取消