Steve Kuo Steve Kuo - 1 year ago 108
Java Question

Java library to get Nth element from a Collection or Iterable

I have a

and need to get the Nth element as returned by its
. I know can iterate while counting through its
elements. Is there a third party library (Google Guava or Apache Commons) that does this?

Answer Source

Guava's Iterators.get(Iterator<T>, int) can help

Advances iterator position + 1 times, returning the element at the positionth position.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download