如果想将List集合转换为指定的键和值的Map,可以使用stream流的toMap方法。
eg: 以对象的productCode字段的值为key,以对象的warehouseCode为值的map集合
Map<String, String> collect = list.stream().collect(Collectors.toMap(TestVO::getProductCode, TestVO::getWarehouseCode));
如果想将List集合转换为指定的键和对象作为值的Map,可以使用stream流的toMap方法。
eg: 以对象的productCode字段的值为key,以对象作为值的map集合
Map<String, TestVO> map = list.stream().collect(Collectors.toMap(TestVO::getProductCode, TestVO-> TestVO));