1
排序的日期比較不起作用。請指教。日期比較失敗d1.compareTo(d2)
代碼:
公共類ListMapComparator實現比較{
@Override
public int compare(Object obj1, Object obj2) {
try {
Map<String, String> test1 = (Map<String, String>) obj1;
Map<String, String> test2 = (Map<String, String>) obj2;
String string1 = test1.get("formattedDate");
String string2 = test2.get("formattedDate");
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
Date d1 = sdf.parse(string1);
Date d2 = sdf.parse(string2);
return d1.compareTo(d2);
} catch (ParseException ex) {
//Logger.getLogger(ListMapComparator.class.getName()).log(Level.SEVERE, null, ex);
}
return 0;
}
}
錯誤: 錯誤:無法找到符號 返回d1.compareTo(D2); 符號:方法compareTo(日期) 位置:變量d1類型日期 注意:某些輸入文件使用或覆蓋棄用的API。 注意:使用-Xlint:deprecation重新編譯以獲取詳細信息。 注意:某些輸入文件使用未檢查或不安全的操作。 注意:使用-Xlint重新編譯:取消選中以獲取詳細信息。