List<List<String>> result = new ArrayList<List<String>>();
List<String> list = new ArrayList<String>();
for(int i = 0;i <50;i++){
list.add(DCF_Ref[i]);
list.add(Type[i]);
list.add(Url[i]);
list.add(hasTitle[i]);
list.add(hasLink[i]);
list.add(imgNo[i]);
list.add(hasVideo[i]);
list.add(hasAudio[i]);
list.add(extraProperties[i]);
result.add(list);
}
然后把result给set到excel里面去,每一个list是一行。
请问这样一个ArrayList result,我应该怎样排序?我希望的是按照DCF_Ref这里面的字母来进行排序。用Collections.sort(result);会报错,Collections.sort(result,camprarator);里面camprarator我又不知该如何写,应该怎么弄呢?
------解决方案--------------------
class MyComprator implements Comparator {
@Override
public int compare(Object result1, Object result2) {
List l1 = (List) result1;
List l2 = (List) result2;
return l1.get(0).toString().compareTo(l2.get(0).toString());
}
}
------解决方案--------------------
Collections.sort(result, new Comparator<String>() {
public int compare(String arg0, String arg1) {
return arg0.compareTo(arg1);
}
});