map-key 排序对比

public static Map<String, List<TPricePpiBaseWeight>> sortMapByKey(Map<String, List<TPricePpiBaseWeight>> map) {
        if (map == null || map.isEmpty()) {
            return null;
        }
        Map<String, List<TPricePpiBaseWeight>> sortMap = new TreeMap<String, List<TPricePpiBaseWeight>>(
                new MapKeyComparator());
        sortMap.putAll(map);
        return sortMap;
    }
import java.util.Comparator;

public class MapKeyComparator implements Comparator<String> {
    @Override
    public int compare(String str1, String str2) {
        return str1.compareTo(str2);
    }
}

 

posted @ 2023-09-19 10:18  chen1777  阅读(18)  评论(0)    收藏  举报