ComparatorChain对List对象的属性排序
来源:互联网 发布:阿里云新能源解决方案 编辑:程序博客网 时间:2024/05/10 02:27
一、按升序 / 降序对List中的对象进行排序
需要使用到对象
org.apache.commons.beanutils.BeanComparator;org.apache.commons.collections.comparators.ComparatorChain;
以下是简单实现
public void test(){
List<FTCoin> list = new ArrayList<FTCoin>();FTCoin ft1 = new FTCoin(8,"ad");FTCoin ft2 = new FTCoin(4,"he");FTCoin ft3 = new FTCoin(9,"bo");FTCoin ft4 = new FTCoin(5,"zh");list.add(ft1);list.add(ft2);list.add(ft3);list.add(ft4);ComparatorChain chain = new ComparatorChain();//false升序排序,true降序排序chain.addComparator(new BeanComparator("id"),false);chain.addComparator(new BeanComparator("coin"),true);Collections.sort(list,chain);for(FTCoin ft:list){ System.out.println(ft.getId()+","+ft.getCoin());}
}
二、输出结果
4,he5,zh8,ad9,bo
0 0
- ComparatorChain对List对象的属性排序
- C#对List 的对象的属性进行排序
- 对List<>中对象的属性进行排序。
- 对List中对象属性进行排序
- 对LIST的对象排序
- Java 对 List 内对象根据对象属性进行排序
- 对list按元素的属性排序
- List 对象属性排序
- 按照list中对象的属性排序
- List 根据对象的属性自定义排序
- 对list集合中的对象按照字段属性排序
- 对List中对象排序
- 对list对象进行排序
- 按bean的属性值对list集合进行排序
- JAVA-对LIST的bean中的某属性排序
- 对List对象列表属性值的快速搜索
- list根据保存的对象的属性排序
- List根据里面的对象属性的值进行排序
- poj 2389 Bull Math(可做大数相乘模板)
- Eclipse 性能和外观设置
- Android Device Monitor查看进程中的有多少个线程在搞
- CAD+开发小结+交互+选择集+深度拷贝AcDbObjectId中指向的实体集+读取其他DWG文件
- BZOJ 1015 并查集
- ComparatorChain对List对象的属性排序
- 杭电1004——Let the Balloon Rise
- javascript图片与加载处理基础详细讲解几种方法实现
- string 内存陷阱
- android中values的良好实践
- 4种排序方式
- Java 架构师推荐书籍
- react img 标签必须闭合,否则报错
- CCF心得体会