Java 怎么获取 Iterable 大小(个数)

 

public class iterableCount {
    public static int iterableCount(Iterable<?> i) {
        int count = 0;
        Iterator<?> it = i.iterator();
        while (it.hasNext()) {
            it.next();
            count++;
        }
        return count;
    }
}

 

posted @ 2020-02-12 19:54  Mr_伍先生  阅读(5828)  评论(1编辑  收藏  举报