我有兩種不同的方法可以從兩個不同的DB表中獲取數據。我將使用bean
類將兩個數據添加到相同的ArrayList
。如何在Java中對Arraylist進行排序
List<LeadVO> leadvoList = new ArrayList<LeadVO>(); // array list declaration
在while loop
我將加載使用bean
類的所有數據。在此操作之前,我將爲兩個表啓動查詢。
while(true){
LeadVO statusVO = new LeadVO(); //initializing bean class
// code to load all value using setters
最後,我將這個bean添加到array list
:
leadvoList.add(statusVO);
創建獨立的類比較
公共類ComparatorDAO實現比較{
public int compare(LeadVO arg0, LeadVO arg1) {
return arg1.getCreatedtimeFormat().compareTo(arg0.getCreatedtimeFormat()) ;
}
}
Collections.sort(commentVOList,new ComparatorDAO()); //排序方法
理想,這將按照日期排序不相信這將處理日期字符串
請再次幫助我,這
感謝
現在我需要解決這按列表中已經存在的日期順序列出。我的意思是列表中的日期。
喜歡[即](HTTP字段中的方法: //stackoverflow.com/questions/2784514/sort-arraylist-of-custom-objects-by-property)? – John 2014-10-31 13:49:23
@Manju我剛剛更新了你的代碼,因爲我沒有測試,所以可能會出現一些小的語法錯誤。 – Lokesh 2014-10-31 13:56:14