有一个列表需要按照【金额: money】【升序】排列,但这个金额是 String 类型的
解决方案
先用mapOrDefault()方法处理空值,再转换为Integer类型进行排序
ListfinalList = list.stream().sorted(Comparator .comparing(mapOrDefault(Entity::getMoney),Comparator.comparingInt(Integer::parseInt))) .collect(Collectors.toList());
自定义的mapOrDefault()方法
private FunctionmapOrDefault(Function func){ //用Optional来设置默认值,如果为空就设置为你想要的规则,比如这里,想放最前面 return vo -> Optional.ofNullable(func.apply(vo)).orElse("0"); }



