Easy way to convert Iterable to Collection

前端 未结 19 2332
忘了有多久
忘了有多久 2020-11-28 01:39

In my application I use 3rd party library (Spring Data for MongoDB to be exact).

Methods of this library return Iterable, while the rest of my

19条回答
  •  孤街浪徒
    2020-11-28 02:36

    Concise solution with Java 8 using java.util.stream:

    public static  List toList(final Iterable iterable) {
        return StreamSupport.stream(iterable.spliterator(), false)
                            .collect(Collectors.toList());
    }
    

提交回复
热议问题