Stream流分组

Stream流分组

将List集合泛型为对象中按照相同的成员属性值进行分组(Map集合)

示例代码

实体类:

@Data
public class Student implements Serializable {
    private Long id;
    private String name;
    private Integer age;
    private String sex;
}

持久层:

public interface Student implements Serializable {
    List<Student> findByStudent();
}
<select id="findByStudent" resultType>
    select * from student
</select>

业务层:

@Service
public class StudentServiceImpl{
    public void show(){
        List<Student> findByStudent = student.findByStudent(sysids);
        Map<String, List<Student>> groupBy = findByStudent.stream().collect(Collectors.groupingBy(Student::getName));
     }
}
THE END
喜欢就支持一下吧
点赞12 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容