Double d2=Double.parseDouble(map2.get(sort_key2).toString());returnasc2?d1.compareTo(d2):d2.compareTo(d1); });returnlist; } 写个demo测试一下 staticvoidtestSort() { List<Map<String, Object>> list =newArrayList<>(); Map<String, Object> item0 =newHashMap<>(); item0.put("pri...
4、多条件排序 我的方案 其实按照博主的方法建立实体类来使用Java 8 stream()新特性进行排序的方式应该是最合适的方式。无奈项目里由于受同事的影响,基本都不建立实体类,所有现在用起来必须用List<Map<String,Object>>来接受查询结果,导致使用stream()方法有点麻烦。感觉建实体类来使用Java 8 新特性会更方便...
List<Map<String, Object>> result =newArrayList<Map<String,Object>>(forcaseResulMap.values());//对list根据里面的map结构的key为time的字段进行排序result=result.stream().sorted((map1,map2)->{returnmap1.get("time").toString().compareTo(map2.get("time").toString()); }).collect(Collectors.t...
/** * 对结果集进行排序,目前支持日期、字符串、各种整形、各种浮点型 * @param result 结果集 * @param order * @param orderType -1降序 1升序, 下面代码假设orderType为1 * @return * @author yutao * @date 2018年4月24日下午2:20:35 */ public static List<Map<String, Object>> resultOrder(L...
if (map1.get("start_time").equals(map2.get("start_time").toString())) { return map2.get("end_time").toString().compareTo(map1.get("end_time").toString()); }else { return map2.get("start_time").toString().compareTo(map1.get("start_time").toString(); } }).collect(Collect...
Map<String, Object> map = new HashMap<String, Object>(); map.put("name", "ZK"); map.put("age", 13); Map<String, Object> map2 = new HashMap<String, Object>(); map2.put("name", "ZA"); map2.put("age", 15); Map<String, Object> map3 = new HashMap<String, Object>()...
List<Map<String,Object>> 集合根据Map里的某个值大小进行排序 实现代码: import java.net.SocketException; import java.net.UnknownHostException; import java.util.*; public class hhh { public static void main(String[] args) throws UnknownHostException, SocketException { ...
*/ public class Ripper { public static void main(String[] args) { Map<String, Object> map = new HashMap<String, Object>(); map.put("name", "ZK"); map.put("age", 13); Map<String, Object> map2 = new HashMap<String, Object>(); map2.put("name", "ZA"); map2.put("age"...
List<Map<String, Object>> list = new ArrayList<>(); Map<String, Object> map1 = new HashMap<>(); Map<String, Object> map2 = new HashMap<>(); Map<String, Object> map3 = new HashMap<>(); map1.put("TIME1", 1); map2.put("TIME13", 2); map3.put("TIME15", 3); list...