- package org.hsyd.test;
- import java.text.CollationKey;
- import java.text.Collator;
- import java.util.Comparator;
- /**
- * 对treeMap排序
- * @author Administrator
- *
- */
- public class CollatorComparator implements Comparator {
- Collator collator = Collator.getInstance();
- public int compare(Object element1, Object element2) {
- CollationKey key1 = collator.getCollationKey(element1.toString());
- CollationKey key2 = collator.getCollationKey(element2.toString());
- return key1.compareTo(key2);
- }
- }
- //这样引用:
- CollatorComparator comparator = new CollatorComparator();
- TreeMap<String, HashMap<Long, Integer>> map=new TreeMap<String, HashMap<Long,Integer>>(comparator);
Java中对TreeMap中文排序
最新推荐文章于 2022-03-09 13:54:06 发布