首页 > 编程知识 正文

collectors是什么品牌,Collectors.groupingBy

时间:2023-05-05 16:58:51 阅读:19245 作者:2385

So,whatconcretetype(subclass ) of List is being used here? Are there any guarantees?

查看Collectors#toList ()文档时,“不能保证返回的List的类型、偏差、可序列化性或线程安全。 若要返回特定实现,请改为使用collectors # to collection (supplier )。

Supplier supplier=() -新链接列表);

List blue=shapes.stream (

. filter(s-s.getcolor ) (==BLUE ) ) ) ) ) ) )。

. collect (collectors.to collection ) supplier );

可以从lambda返回到您想要的List Shape实现。

更新:

或者,也可以用方法引用:

List blue=shapes.stream (

. filter(s-s.getcolor ) (==BLUE ) ) ) ) ) ) )。

. collect (collectors.to collection )链接列表3360: new );

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。