so ich habe jetzt so ein Objekt. Eingabe ein beliebige Liste. das Problem ist, ich weiß nie vorher wieviel elemente rows[x] hat.
rows= [{col1=1, col3=Nachname_1, col2=Vorname_1}, {col1=2, col3=Nachname_2, col2=Vorname_2}].
RowID=2 // z.B. zweite Zeile
ColmnName="col2";
Meine Ausgabe soll Vorname_2 sein.
ich weiß, das ist sehr umständlich. wie kann ich das schöner schreiben?
[code=Java]
void Column(List rows, int RowID, String ColmnName){
System.out.printf("Ausgabe für %s Zeile %d\n",ColmnName,RowID);
Map Row= new HashMap();
String test3 = rows.get(RowID).toString();
test3=test3.replace("{","");
test3=test3.replace("}","");
System.out.printf("%s\n",test3);
String[] DataTemp=test3.split(",");
for(int i=0;i<DataTemp.length;i++){
String[] colData=new String[2];
colData=DataTemp[i].split("=");
Row.put(colData[0], colData[1]);
System.out.printf("Ausgabe Name %s Value %s\n",colData[0],colData[1]);
}
System.out.print("\n");
System.out.print(Row);
System.out.print("\n");
System.out.print(Row.get("col2"));
}
[/code]