This example will show how to find the last element in an ArrayList. While this may seem trivial, utilities exist to provide a more readable, eloquent approach vs the solution outlined in the straight up java section.
Straight up Java
This snippet will get the last element in a ArrayList using straight up java. It will check if the ArrayList is empty and if the size is greater than 0 returning the last element in the collection.
Guava Iterables.getLast will return the last element in the iterable or the default value if the list is empty.
Apache commons CollectionUtils.get will return the element at the last index.