From Google Guava JavaDoc for Iterables:
static <T> T getFirst(Iterable<T> iterable, T defaultValue) -> Returns the first element in iterable or defaultValue if the iterable is empty.
static <T> T getLast(Iterable<T> iterable) -> Returns the last element of iterable.
static <T> T getLast(Iterable<T> iterable, T defaultValue) -> Returns the last element of iterable or defaultValue if the iterable is empty.
One static method is missing (to me):
static <T> T getFirst(Iterable<T> iterable) -> Returns the first element of iterable.
Do you know the reason for this inconsistency?
Because it's too simple to justify a helper method. The method would just be iterable.iterator().next() and would have behavior exactly analogous to getLast().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With