简体   繁体   English

将拆分器转换为 Java 中的列表的最佳习语是什么?

[英]What is the best idiom to convert a spliterator to a list in Java?

I want to convert a Spliterator<T> into a List<T> in Java.我想将Spliterator<T>转换为 Java 中的List<T>

What is the best idiom to do that?最好的成语是什么? I'm currently using the following code:我目前正在使用以下代码:

 List<T> list = new ArrayList<>();
 spliterator.forEachRemaining(list::add);

Is there a simpler / faster way?有没有更简单/更快的方法?

You can use this:你可以使用这个:

 StreamSupport.stream(spliterator, false).collect(Collectors.toList())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM