/** * List<Map>根据map字段排序 * * @param list * @param feild 排序字段 * @param sortTyp 排序方式 desc-倒序 asc-正序 * @return */ public static List<Map<String, Object>> sortByFeild(List<Map<String, Object>> list, String feild, String sortTyp) { if (CollectionUtils.isNotEmpty(list)) { list.sort((m1, m2) -> { if (StringUtils.equals(sortTyp, "desc")) { return String.valueOf(m2.get(feild)).compareTo(String.valueOf(m1.get(feild))); } else { return String.valueOf(m1.get(feild)).compareTo(String.valueOf(m2.get(feild))); } }); // 或者 Collections类里面的sort方法也是list.sort()与上面一样 // Collections.sort(list, (m1, m2)-> String.valueOf(m1.get(feild)).compareTo(String.valueOf(m2.get(feild)))); // lamuda排序 } return list; }
标签:map,java,String,get,valueOf,list,listmap,m1,feild From: https://www.cnblogs.com/ssbxfsrm/p/17170695.html