我有列表列表(列表行包含列表列)。我想按长度(.size())对 ListRZS 中的行进行排序。
[[123, 189, 277], [11], [145, 211, 299], [156, 222, 310], [167, 233, 255], [189, 266], [200, 277], [211, 288], [245, 299], [233], [244]]
Shoul be:
[[11], [233], [244], [189, 266],[200, 277], [211, 288], [245, 299], [123, 189, 277], [145, 211, 299], [156, 222, 310], [167, 233, 255]]
问题:如何为这种情况编写工作比较器/可比较。
public class Start {
public static void main(String[] args) {
System.out.println("Start reading from Xls");
ReaderXls1Column read = new ReaderXls1Column();
ReaderXls readrzs = new ReaderXls();
List<String> listASU = new ArrayList<String>(read.ReaderXls1Column("Text1obj",0,1)); // Creating Lists
List<List<String>> listRZS = new ArrayList<List<String>>(readrzs.ReadXls("Text1obj",2,12));
System.out.println(listASU);
System.out.println(listRZS);
System.out.println("Reading is over");
System.out.println(listRZS);
WriterXls.main("Text1obj",listRZS);
System.out.println("Writing is over");
}
我没有比较器的尝试,可比较(当然,不能正常工作)
int k=0;
while ( k<listRZS.size()){
for (int j=0;j<10;j++) {
List<String> tmplist = new ArrayList<String>();
if (listRZS.get(k).size()>listRZS.get(k+1).size()) {Collections.copy(listRZS.get(k),tmplist); listRZS.remove(k); listRZS.add(k+1,tmplist);}
else {};
}
Collections.sort(listRZS.get(k)); // sort each row, solution above
k++;
}