Easy way to convert Iterable to Collection

前端 未结 19 2306
忘了有多久
忘了有多久 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:43

    You may write your own utility method for this as well:

    public static  Collection makeCollection(Iterable iter) {
        Collection list = new ArrayList();
        for (E item : iter) {
            list.add(item);
        }
        return list;
    }
    

提交回复
热议问题