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

来源:互联网 发布:javascript focus用法 编辑:程序博客网 时间:2024/06/11 00:44
/** * 对含有map的list排序 * * @param areaList 原始值 * @param isDesc   TRUE:从大到小  FALSE:从小到大 */public static void sortListMap(List<Map.Entry<String, Double>> areaList, final boolean isDesc) {    Collections.sort(areaList, new Comparator<Map.Entry<String, Double>>() {        public int compare(Map.Entry<String, Double> o1,                           Map.Entry<String, 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进行排序 * <p> * 2017年9月29日 17:19:09 * xj * * @param list   List<Map<String,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<String, Object> o1Map = (Map<String, Object>) o1;            Map<String, Object> o2Map = (Map<String, 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

原创粉丝点击