Search code examples
javacollectionsiterable

Java: Get first item from a collection


If I have a collection, such as Collection<String> strs, how can I get the first item out? I could just call an Iterator, take its first next(), then throw the Iterator away. Is there a less wasteful way to do it?


Solution

  • Iterables.get(yourC, indexYouWant)

    Because really, if you're using Collections, you should be using Google Collections.