我有两种不同的方法可以从两个不同的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