Get size of an Iterable in Java

前端 未结 10 1236
半阙折子戏
半阙折子戏 2020-12-08 03:48

I need to figure out the number of elements in an Iterable in Java. I know I can do this:

Iterable values = ...
it = values.iterator();
while (i         


        
10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 04:06

    Why don't you simply use the size() method on your Collection to get the number of elements?

    Iterator is just meant to iterate,nothing else.

提交回复
热议问题