This example will find the first non null element in an array using java, java 8, guava and apache commons.
Straight up Java
Iterating over the collection using a for each loop an if statement will check that an element is not null. The first non null value will break out of the loop otherwise the firstNonNull variable will remain null.
Java 8
This snippet will find the first non null element in an arraylist using Java 8. The Streams API contains Stream.Filter which will return elements that match a predicate. By passing a java predicate via a lambda expression, the stream will filter elements not equaling null. If any elements match the Stream.findFirst will return an java Optional that describes the element. If no elements match an empty optional will be returned.
Google Guava
This snippet will show how to find the first element in an array list using guava. Passing a guava predicate returning true if an object isn't null, the Iterables.find will return the first element that matches.
Apache Commons
This snippet will use apache commons to find the first element in a collection. ObjectUtils.firstNonNull will return the first value in an array that isn't null. We will convert the given array list to an array by calling list.toArray.