我有字符串數組的ArrayList,已經低於聚集串
{"name","sname","Id1","Id2","type","LDP","oldvalue","newvalue"}
{"test1","abc","20","50","t1","SD1","0","1"}
{"test2","znc","21","23","t1","SF5","3","4"}
{"test1","abc","20","50","t1","SD3","0","1"}
{"test1","HJc","53","50","t1","SD3","0","1"}
{"test2","znc","21","23","t1","SF1","1","6"}
{"test1","abc","20","50","t1","SD5","2","19"}
{"test3","ldb","19","54","t1","SR51","6","1"}
{"test2","znc","21","23","t1","SF12","17","36"}
{"test3","ldb","19","54","t1","SR44","19","31"}
{"test4","lYI","76","56","t1","TB77","54","87"}
我想有通過排序此電流ArrayList的一個新的ArrayList(列和行)的值填充並獲得線使用相同的鍵(順序:名稱,名稱,Id1,Id2,類型),將它們的值在一行中連接(用;分隔)在一行中。
預期輸出:
{"name","sname","Id1","Id2","type","Comment"}
{"test1","abc","20","50","t1","SD1,0,1; SD3,0,1; SD5,2,19"}
{"test1","HJc","53","50","t1","SD3,0,1"}
{"test2","znc","21","23","t1","SF5,3,4; SF1,1,6; SF12,17,36"}
{"test3","ldb","19","54","t1","SR44,19,31;SR51,6,1 }
{"test4","lYI","76","56","t1","TB77,54,87"}
我的ArrayList是從結果查詢生成:
// header
String[] myString0 = {"name","sname","Id1","Id2","type","LDP","oldvalue","newvalue"};
//lines
while (rset.next()) {
String name = rset.getString("name");
String sname = rset.getString("sname");
String Id1 = rset.getString("Id1");
String Id2 = rset.getString("Id2");
String type = rset.getString("type");
String LDP = rset.getString("LDP");
String oldvalue = rset.getString("oldvalue");
String newvalue = rset.getString("newvalue");
String[] myString1 = {name, sname, Id1, Id2, "type", LDP, oldvalue, newvalue};
outerArr.add(myString1);// my Arraylist
}
}
感謝,
你舉的例子是模糊的(以我?)。你是怎麼定的。按什麼排序?如何連接值?請描述這些事情。 –
感謝您的回覆,按名稱排序,名稱,Id1,Id2,類型(作爲鍵) –
一種方法是創建一個代表您的密鑰的類。說那是MyKey。現在您可以創建一個HashMap>。將每一行添加到地圖中的列表中,如有必要,創建一個條目。現在只需遍歷地圖中的條目。對於每個條目,從該條目列表中的記錄創建摘要行。 –