标签:str rri help arraylist any ide div 拼音 cti
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(); }
标签:str rri help arraylist any ide div 拼音 cti
原文地址:https://www.cnblogs.com/mr-wuxiansheng/p/10861299.html