List集合String字符串按照汉语拼音排序
public static void main(String[] args) {
        List<Map<String, Object>> mapList = new ArrayList<Map<String,Object>>();
        Map<String, Object> m1 = new HashMap<String,Object>();
        m1.put("name", "AC");
        Map<String, Object> m2 = new HashMap<String,Object>();
        m2.put("name", "AB");
        Map<String, Object> m3 = new HashMap<String,Object>();
        m3.put("name", "中国");
        Map<String, Object> m4 = new HashMap<String,Object>();
        m4.put("name", "广东");
        Map<String, Object> m5 = new HashMap<String,Object>();
        m5.put("name", "B东");
        Map<String, Object> m6 = new HashMap<String,Object>();
        m6.put("name", "C东");
        mapList.add(m1);
        mapList.add(m2);
        mapList.add(m3);
        mapList.add(m4);
        mapList.add(m5);
        mapList.add(m6);
        if(CollectionUtils.isNotEmpty(mapList)){
            Collections.sort(mapList, new Comparator<Map<String,Object>>() {
                @Override
                public int compare(Map<String,Object> m1, Map<String,Object> m2) {
                    String o1 = (String) m1.get("name");
                    String o2 = (String) m2.get("name");
                    char c1 = ((String) o1).charAt(0);
                    char c2 = ((String) o2).charAt(0);
                    return concatPinyinStringArray(PinyinHelper.toHanyuPinyinStringArray(c1)).compareTo(
                            concatPinyinStringArray(PinyinHelper.toHanyuPinyinStringArray(c2)));
                }
            });
        }
        for (Map<String, Object> map : mapList) {
            System.out.println("map:"+(String)map.get("name"));
        }
    }
    private static String concatPinyinStringArray(String[] pinyinArray) {
        StringBuffer pinyinSbf = new StringBuffer();
        if ((pinyinArray != null) && (pinyinArray.length > 0)) {
            for (int i = 0; i < pinyinArray.length; i++) {
                pinyinSbf.append(pinyinArray[i]);
            }
        }
        return pinyinSbf.toString();
    }  
List集合String字符串按照汉语拼音排序的更多相关文章
- 集合或数组转成String字符串
		
1.将集合转成String字符串 String s=""; for (int i = 0; i < numList.size(); i++) { if (s=="& ...
 - 新疆大学OJ(ACM) 1047: string   字符串排序
		
1047: string 时间限制: 1 Sec 内存限制: 128 MB 题目描述 有n个字符串字符串n<=50000,把所有字符串串起来,得到一个字典序最小的字符串. 输入 输入第一行是一 ...
 - Map 集合 和 String 字符串相互转换工具类
		
package com.skynet.rimp.common.utils.util; import java.util.Arrays; import java.util.HashMap; import ...
 - 判断集合中存在String字符串 或 判断集合中不存在String字符串
		
一.使用场景 用于集合中有多个相近的字符,无法使用包含判断 如: 这里如果我想判断以上集合中是否包含"信封件-DE"就会被"信封件-DE2"影响到 毕竟:&qu ...
 - Java中各种集合(字符串类)的线程安全性!!!
		
Java中各种集合(字符串类)的线程安全性!!! 一.概念: 线程安全:就是当多线程访问时,采用了加锁的机制:即当一个线程访问该类的某个数据时,会对这个数据进行保护,其他线程不能对其访问,直到该线程读 ...
 - 程序兵法:Java String 源码的排序算法(一)
		
摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠BYSocket 」欢迎关注和转载,保留摘要,谢谢! 这是泥瓦匠的第103篇原创 <程序兵法:Java Str ...
 - [CareerCup] 1.3 Permutation String 字符串的排列
		
1.3 Given two strings, write a method to decide if one is a permutation of the other. 这道题给定我们两个字符串,让 ...
 - 对list集合中的对象进行排序(转载)
		
原文链接:http://blog.csdn.net/veryisjava/article/details/51675036 Collections对List集合中的数据进行排序 有时候需要对集合中的元 ...
 - Java Map集合按照key和value排序之法
		
一.理论基点 Map是键值对的集合接口,它的实现类主要包括:HashMap,TreeMap,Hashtable以及LinkedHashMap等. TreeMap:基于红黑树(Red-Black-Tre ...
 
随机推荐
- 洛谷 P4017 最大食物链计数 题解
			
P4017 最大食物链计数 题目背景 你知道食物链吗?Delia生物考试的时候,数食物链条数的题目全都错了,因为她总是重复数了几条或漏掉了几条.于是她来就来求助你,然而你也不会啊!写一个程序来帮帮她吧 ...
 - .Net Core  EF 使用整理合集
			
1..NetCore中EFCore的使用整理 2..NetCore中EFCore的使用整理(二)-关联表查询 3.EF Core 1.0 和 SQLServer 2008 分页的问题 4.EF Cor ...
 - -bash: /bin/grep: Argument list too long和 find: Arguments to -type should contain only one letter报错处理
			
由于要查找的文件太多 过滤成只找具体时间一天以内的文件 | 查找最近30分钟修改的当前目录下的.php文件 查找最近24小时修改的当前目录下的.php文件 查找最近24小时修改的当前目录下的.php文 ...
 - 常见的SQL优化面试题
			
1.在表中建立索引,优先考虑where.group by使用到的字段. 2.查询条件中,一定不要使用select *,因为会返回过多无用的字段会降低查询效率.应该使用具体的字段代替*,只返回使用到的字 ...
 - mysql Last_SQL_Errno: 1197 Coordinator stopped because there were error(s) in the worker(s)问题处理
			
Last_SQL_Errno: 1197 Coordinator stopped because there were error(s) in the worker(s). The most rece ...
 - js 经常用于条件判断 大于等于0 的正整数
			
/^\d+(?=\.{,}\d+$|$)/.test() // true 转:https://www.jianshu.com/p/feef5e62dd67
 - shell中跳出循环语句break和continue
			
在使用while或for循环语句过程中,也许碰到某个特殊条件,我们需要跳过当次循环或整个循环,这是就需要借助break和continue. break表示跳出本层循环,break n表示跳出循环的层数 ...
 - 如何用谷歌浏览器导出一个https网站的数字证书
			
HTTPS加密是互联网安全建设的基础,百度.淘宝.天猫等越来越多互联网巨头启用全站HTTPS,也带动了更多网站加入HTTPS加密的行列.普通用户也逐渐明白HTTPS比HTTP更安全,访问网银.购物等重 ...
 - [LeetCode] 499. The Maze III 迷宫 III
			
There is a ball in a maze with empty spaces and walls. The ball can go through empty spaces by rolli ...
 - consul删除无效实例
			
consul删除无效实例删除无效服务删除无效节点删除无效服务http://127.0.0.1:8500/v1/agent/service/deregister/test-9c14fa595ddfb8f ...