Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java library to get Nth element from a Collection or Iterable

Tags:

java

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

like image 608
Steve Kuo Avatar asked Feb 01 '13 19:02

Steve Kuo


1 Answers

Guava's Iterators.get can help

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

like image 98
Reimeus Avatar answered Oct 23 '22 12:10

Reimeus