发布网友 发布时间:2022-04-22 22:52
共2个回答
热心网友 时间:2023-10-07 06:55
Collections.reverse(list);
试试这个。
List l = new ArrayList();热心网友 时间:2023-10-07 06:55
/**
* 根据日期排序与
*
* @param list
* @param index
* @param sort
* 排序方式 desc 为逆序 ,其他为顺序
* @return
*/
public static List<String[]> OrderByDate(List<String[]> list, int index,
String sort) {
List<String[]> result = new ArrayList<String[]>();
DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
List<Date> dateList = new ArrayList<Date>();
for (String[] str : list) {
try {
dateList.add(sdf.parse(str[index]));
} catch (ParseException e) {
e.printStackTrace();
}
}
Date temp = dateList.get(0);
if (dateList != null && dateList.size() > 0) {
if (sort.equals("desc")) {
for (Date date : dateList) {
for (int i = 0; i < dateList.size(); i++) {
if (temp.after(dateList.get(i))) {
temp = dateList.get(i);
}
}
}
}else{
for (Date date : dateList) {
for (int i = 0; i < dateList.size(); i++) {
if (temp.before(dateList.get(i))) {
temp = dateList.get(i);
}
}
}
}
}
for (String[] str : list) {
try {
Date date = sdf.parse(str[index]);
if (date.equals(temp)) {
result.add(str);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
return result;
}追问应该怎么用呢 粘贴上去有错误啊