Related questions
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 …
Why there is no getFirst(iterable) method?
Iterables present two methods for getLast
public static <T> T getLast(Iterable<T> iterable);
public static <T> T getLast(Iterable<T> iterable, @Nullable T defaultValue);
but only one for getFirst
public static &…
Contains method for Iterable and Iterator?
Is there a simple method to check if an element is contained in an iterable or iterator, analogous to the Collection.contains(Object o) method?
I.e. instead of having to write:
Iterable<String> data = getData();
for (final …