Java中如何使用StreamCollectors收集器-创新互联
                                            Java中如何使用Stream Collectors收集器?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

Collectors.toMap:
Student studentA = new Student("20190001","小明");
    Student studentB = new Student("20190002","小红");
    Student studentC = new Student("20190003","小丁");
    //Function.identity() 获取这个对象本身,那么结果就是Map 即 id->student
    //串行收集
   Stream.of(studentA,studentB,studentC)
        .collect(Collectors.toMap(Student::getId,Function.identity()));
    //并发收集
    Stream.of(studentA,studentB,studentC)
        .parallel()
        .collect(Collectors.toConcurrentMap(Student::getId,Function.identity()));
    //================================================================================
    //Map 即 id->name
    //串行收集
    Stream.of(studentA,studentB,studentC)
        .collect(Collectors.toMap(Student::getId,Student::getName));
    //并发收集
    Stream.of(studentA,studentB,studentC)
        .parallel()
        .collect(Collectors.toConcurrentMap(Student::getId,Student::getName));                                                  网站题目:Java中如何使用StreamCollectors收集器-创新互联
当前网址:http://www.jxjierui.cn/article/hepjs.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 