0
에 행을 변환 복잡한 :나는이 코드를 가지고 열 배열
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
수정 해 주시겠습니까?
여기에 게시하기 전에 디버그 모드에서 테스트 해 보셨습니까 ?? – MissingNumber
사용 된 데이터 구조가 필수입니까, 아니면 자유롭게 변경할 수 있습니까? –
그 결과는 무엇입니까? 당신이 제공 한 결과를 어떻게 인쇄 했습니까? 해당 코드 스 니펫을 표시 할 수 있습니까? – sp00m