开发工具类
1. 集合之间相互转换
1.1 List转Map
1、Java8之前的办法
新建一个map,挨个放进去
2、Java8的方法
//key值对应一个 value
Map<String, InsuranceRenewalPo> map = insuranceRenewalPos.stream().collect(
Collectors.toMap(InsuranceRenewalPo::getOrderNo, Function.identity()));
//key值对应多个 value
Map<String,List<InsuranceRenewalPo>> mapByPolicyNo =
insuranceRenewalPos.stream().collect(Collectors.groupingBy(InsuranceRenewalPo::getPolicyNo));
3、使用Guava
Map<Integer, Animal> map = Maps.uniqueIndex(list, Animal::getId);
4、使用Apache common
Map<Integer, Animal> map = new HashMap<>();
MapUtils.populateMap(map, list, Animal::getId);