![](/img/trans.png)
[英]What is forEach and spliterator in Iterable interface, and how to implement with linked list
[英]What is the best idiom to convert a spliterator to a list in Java?
我想將Spliterator<T>
轉換為 Java 中的List<T>
。
最好的成語是什么? 我目前正在使用以下代碼:
List<T> list = new ArrayList<>();
spliterator.forEachRemaining(list::add);
有沒有更簡單/更快的方法?
你可以使用這個:
StreamSupport.stream(spliterator, false).collect(Collectors.toList())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.