本文介绍了 Java Stream API 的多种实用场景,包括属性抽取、集合转换、字段拼接、List 转 Map、分组及排序等操作。通过具体代码示例展示了如何简化集合处理任务。
文章目录
// 将集合中的某个属性单独抽取为list或setSet<Long> set = userList.stream().map(User::getId).collect(Collectors.toList());Set<Long> set = userList.stream().map(User::getId).collect(Collectors.toSet());