I have a collection, I want to get the last element of the collection. What\'s the most straighforward and fast way to do so?
One solution is to first toArray(), and
If you have Iterable convert to stream and find last element
Iterator sourceIterator = Arrays.asList("one", "two", "three").iterator(); Iterable iterable = () -> sourceIterator; String last = StreamSupport.stream(iterable.spliterator(), false).reduce((first, second) -> second).orElse(null);