jdk 8
菜鸟阿达
爱编程,爱折腾!爱运动,爱生活!
展开
-
java8将List<TbUser>进行两层分组
用户democlass TbUser{ private int age; private int sex;}1.返回值方式一Map<Integer,<Integer,List<TbUser>>> result = users.stream().collect(Collectors.groupingBy(TbUser::getAge, Collectors.groupingBy(TbUser::getSex)));2.返回值方式二Map<Inte原创 2022-04-08 11:22:36 · 1706 阅读 · 0 评论 -
java8将List<T>分组求和并返回 List<T>
将List 分组求和 并返回 List如下示例 :计算 同组用户的年龄和List<User> users = new ArrayList<>();// ... add user to usersMap<String, User> groupByModelId = users.stream() .collect(Collectors.toMap(User::getGroupId, Function.identity(), (m1, m2) -原创 2021-04-08 16:32:18 · 3567 阅读 · 0 评论 -
JAVA8 lambda将集合均等分成N份
利用流将集合均等分配成N 份参考 https://www.it610.com/article/1305408041658650624.htmList<String> names = ....;long pageNum = 20;long limit = (names.size() + pageNum - 1) / pageNum;List<List<String>> groupNames = Stream.iterate(0, n -> n + 1)原创 2021-03-26 13:44:31 · 2018 阅读 · 0 评论