我得到了这些代码:
String[] s1={"Samsung Smarphone","20MB"};
String[] s11={"Apple Smarphone","25MB"};
String[] s2={"Samsung Smarphone","3 in"};
String[] s22={"Apple Smarphone","6 in"};
String[] s3={"Samsung Smarphone","3GB"};
String[] s33={"Apple Smarphone","2 GB"};
String[] s4={"Apple Smarphone","iphone1"};
String[] s44={"Apple Smarphone","iphone2"};
String[] s444={"Apple Smarphone","iphone3"};
List<String[]> l1=new ArrayList<String[]>();
l1.add(s1);
l1.add(s11);
List<String[]> l2=new ArrayList<String[]>();
l2.add(s2);
l2.add(s22);
List<String[]> l3=new ArrayList<String[]>();
l3.add(s3);
l3.add(s33);
List<String[]> l4=new ArrayList<String[]>();
l4.add(s4);
l4.add(s44);
l4.add(s444);
Vector<List<String[]>> myV=new Vector<List<String[]>>();
myV.add(l1);
myV.add(l2);
myV.add(l3);
myV.add(l4);
List<String[]> resultL=new ArrayList<String[]>();
String[] mainS={"Samsung Smarphone","Apple Smarphone","Apple Smarphone","Apple Smarphone"};
for (int i=0; i<mainS.length; i++){
String[] theRow=new String[myV.size()+1];
for (int k=0; k<myV.size(); k++){
List<String[]> smallList=(List<String[]>)myV.elementAt(k);
String[][] small2DArr=new String[smallList.size()][2];
smallList.toArray(small2DArr);
String strMain=mainS[i];
int rows=small2DArr.length;
int cols=2;
for( int y=0; y<rows; y++)
{
for(int z=0; z<cols; z++){
String str=small2DArr[y][z];
if(strMain.equals(str))
{
theRow[0]=strMain;
theRow[k+1]=small2DArr[y][1];
}
}
}
}
resultL.add(theRow);
}
for(int u=0; u<resultL.size(); u++)
{
String[] myR=resultL.get(u);
//int ddd=xxx.length;
System.out.println("\n----------------\n");
for (String s : myR)
{
System.out.print(s +"\t");
}
}
结果是:
Samsung Smarphone 20MB 3 in 3GB null
----------------
Apple Smarphone 25MB 6 in 2 GB iphone3
----------------
Apple Smarphone 25MB 6 in 2 GB iphone3
----------------
Apple Smarphone 25MB 6 in 2 GB iphone3
上面的结果是不正确的。我想要这样的结果:
Samsung Smarphone 20MB 3 in 3GB null
----------------
Apple Smarphone 25MB 6 in 2 GB iphone1
----------------
Apple Smarphone 25MB 6 in 2 GB iphone2
----------------
Apple Smarphone 25MB 6 in 2 GB iphone3
你能帮我修一下吗?