In a traditional approach we will capture the first element in the list length setting it to a variable named shortest. Next we will loop over a list checking each element and comparing it to the shortest length. If the length is less than the previous we will set the shortest element to the current element. Finally in a junit assert we will validate that the smallest length string is Zachary Taylor.
Java 8
Using java 8 lambda expression, we will create a java Comparator that will check the length of string which would make the list ascending. Converting a list to a stream calling sorted we will pass the comparator in reverse since we want the shortest first. Finally, calling the findFirst will return the first element wrapped in Optional.
Google Guava
Using guava fluent ordering class we will compare the length of the strings and pass the ordering object to Collections.sort. In our assert we will use the Iterables.getFirst to retrieve the first element in the list.