Iterables present two methods for getLast
public static T getLast(Iterable iterable);
public static T getLast(It
As an additions to @JohnB's answer I'd like to show Guava's devs opinion about getFirst(iterable). Kevin Bourrillion (head Guava's dev) writes there:
iterable.iterator().next() is perfectly clear and readable and unambiguous. I know exactly what it does, whereas with Iterators.getFirst(), I have to run off and look up how that library designer decided to do it.
Also, your notion of consistency is deeply misguided. We use consistency in how we present important functionality, but we never use it to justify adding worthless functionality, and you shouldn't in your own libraries either!
So, you have a choice:
iterable.iterator().next()
,Iterables.getFirst(Iterable iterable, T default)
,Iterables.get(Iterable, 0)
,iterable.iterator().next()
and some docs) and use it as i.e. Iterables2.getFirst(iterable)
,PS: I had similar doubt some time ago and found exact duplicate of this question at that time.