排序不正确写法:
List<Map<String,Object>> sortList2 = list.stream().sorted((o1, o2) -> { if (o1.get("DAY_ACTUAL").toString().compareTo(o2.get("DAY_ACTUAL").toString()) > 0) { return -1; } else return 1; }).collect(Collectors.toList());
排序不正确,需将 字符串转为 double 再排序
报错写法:
List<Map<String,Object>> sortList2 = list.stream().sorted((o1, o2) -> { if ((Double)(o1.get("DAY_ACTUAL").toString().compareTo(Double)(o2.get("DAY_ACTUAL").toString()) > 0) { return -1; } else return 1; }).collect(Collectors.toList());
解决方法:
将基础类型double转为java封装的Double类
调整后写法:
List<Map<String,Object>> sortList2 = list.stream().sorted((o1, o2) -> { if (new Double(o1.get("DAY_ACTUAL").toString()).compareTo(new Double(o2.get("DAY_ACTUAL").toString())) > 0) { return -1; } else return 1; }).collect(Collectors.toList());
标签:lang,ACTUAL,java,get,return,报错,toString,o2,o1 From: https://www.cnblogs.com/moonsoft/p/16812738.html