- 指定key-value,value为对象本身
AgentBalanceDTO->AgentBalanceDTO是一个返回本身的lambda表达式
Map<String, AgentBalanceDTO> agentBalance =
list.stream().collect(Collectors.toMap(AgentBalanceDTO::getFinancialCode, AgentBalanceDTO -> AgentBalanceDTO));
- 指定key-value,key-value均为对象属性
Map<String,String> map = list.stream().collect(Collectors.toMap(对象::get属性,对象::get属性));
- 提取List对象的某一列值及去重
去重使用distinct()方法
// 提取list对象中的某一列值不去重
List<String> prefixList = list.stream().map(对象::getPrefix).collect(Collectors.toList();
// 去重操作
List<String> prefixList = list.stream().map(对象::getPrefix)
.distinct().collect(Collectors.toList();
- 提取过滤后对象中的某个值
List<String> noList = ticketDetailDTOS.stream().filter(ticket -> !Objects.equals("5", ticket.getStockStatus())).map(TicketDetailDTO::getNo).collect(Collectors.toList());