• java实现按拼音排序


    List<WaPayFileVO> list =(List<WaPayFileVO>) dao.execQueryBeanList(pagesql, params.toArray(),  new BeanListProcessor(WaPayFileVO.class));
    
     if("asc".equals(page.getOrder()) && "pk_psnjob__pk_psndoc__name".equals(page.getSort())){
                Collections.sort(list, new Comparator<WaPayFileVO>() {
                    @Override
                    public int compare(WaPayFileVO o1, WaPayFileVO o2) {
                        return Collator.getInstance(Locale.CHINESE).compare(o1.getPk_psnjob__pk_psndoc__name(),o2.getPk_psnjob__pk_psndoc__name());
                    }
                });
            }else if("desc".equals(page.getOrder()) && "pk_psnjob__pk_psndoc__name".equals(page.getSort())){
                Collections.sort(list, new Comparator<WaPayFileVO>() {
                    @Override
                    public int compare(WaPayFileVO o1, WaPayFileVO o2) {
                        return -Collator.getInstance(Locale.CHINESE).compare(o1.getPk_psnjob__pk_psndoc__name(),o2.getPk_psnjob__pk_psndoc__name());
                    }
                });
            }

    jdk自带的Collator包涵的汉字太少了,对一些生僻的姓氏不能进行排序。推荐使用:

    import com.ibm.icu.text.Collator; 

    是ibm开发的针对编码的工具包,非常好用。附pom文件:

    <dependency>  
                <groupId>com.ibm.icu</groupId>  
                <artifactId>icu4j</artifactId>  
                <version>57.1</version>  
            </dependency> 
  • 相关阅读:
    CCF NOI1062 计算曼哈顿距离
    CCF NOI1061 Wifi密码
    CCF NOI1073 放苹果
    CCF NOI1072 爬楼梯
    CCF NOI1071 Pell数列
    CCF NOI1064 计算斐波那契第n项
    NOI训练行动路线图
    CCF NOI1060 雷同检测
    CCF NOI1059 表达式求值
    CCF NOI1057 石头剪刀布
  • 原文地址:https://www.cnblogs.com/skyislimit/p/10167581.html
Copyright © 2020-2023  润新知