Skip to content
Advertisement

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?

Advertisement

Answer

Iterables.get(yourC, indexYouWant)

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

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement