Util工具类 对map中含有String类型的日期key值的list进行排序

/**
 * 对含有map的list排序
 *
 * @param areaList 原始值
 * @param isDesc   TRUE:从大到小  FALSE:从小到大
 */
public static void sortListMap(List, Double>> areaList, final boolean isDesc) {
    Collections.sort(areaList, new Comparator, Double>>() {
        public int compare(Map.Entry, Double> o1,
                           Map.Entry, Double> o2) {
            int flag = 1;
            if (isDesc) {
                if (o2.getValue() - o1.getValue() < 0) {
                    flag = -1;
                }
            } else {
                if (o2.getValue() - o1.getValue() > 0) {
                    flag = -1;
                }
            }

            return flag;
        }
    });
}

/**
 * 对map中含有String类型的日期key值的list进行排序
 * 

* 2017年9月29日 17:19:09 * xj * * @param list List,Object>>,String为日期 * @param format 日期格式 * @param isDesc TRUE:从大到小 FALSE:从小到大 */ public static void sortListStringDateMap(List list, final String format, final boolean isDesc) { Collections.sort(list, new Comparator() { @Override public int compare(Object o1, Object o2) { Map, Object> o1Map = (Map, Object>) o1; Map, Object> o2Map = (Map, Object>) o2; String o1Key = ""; for (String key : o1Map.keySet()) { o1Key = key; } String o2Key = ""; for (String key : o2Map.keySet()) { o2Key = key; } Integer o1K = Integer.valueOf(Util.transformDateToString(Util.transformStringToDate(o1Key, format), "yyyyMMdd")); Integer o2K = Integer.valueOf(Util.transformDateToString(Util.transformStringToDate(o2Key, format), "yyyyMMdd")); int flag = 1; if (isDesc) { if (o2K - o1K < 0) { flag = -1; } } else { if (o2K - o1K > 0) { flag = -1; } } return flag; } }); }


更多工具类方法:http://blog.csdn.net/qq_34117825/article/details/78392976

你可能感兴趣的:(Java,Util)