@@ -0,0 +1,1550 @@
+package com.levelup.java.collections;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport org.apache.commons.lang3.ObjectUtils;%0Aimport org.junit.Test;%0A%0Aimport com.google.common.base.Predicates;%0Aimport com.google.common.collect.Iterables;%0Aimport com.google.common.collect.Lists;%0A%0A/**%0A * This java example will demonstrate finding %0A * the first non null object in a list.%0A * %0A * @author Justin Musgrove%0A * @see %3Ca href='http://www.leveluplunch.com/java/'%3EFind first non null%3C/a%3E%0A * %0A */%0Apublic class FindFirstNonNull %7B%0A%0A%09@Test%0A%09public void find_first_non_null_list_java () %7B%0A%0A%09%09List%3CString%3E strings = new ArrayList%3CString%3E();%0A%09%09strings.add(null);%0A%09%09strings.add(%22Hello%22);%0A%09%09strings.add(null);%0A%09%09strings.add(%22World%22);%0A%0A%09%09String firstNonNull = null;%0A%09%09for (String string : strings) %7B%0A%09%09%09if (string != null) %7B%0A%09%09%09%09firstNonNull = string;%0A%09%09%09%09break;%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09assertEquals(%22Hello%22, firstNonNull);%0A%09%7D%0A%0A%09@Test%0A%09public void find_first_non_null_list_guava () %7B%0A%0A%09%09List%3CString%3E strings = Lists.newArrayList(%0A%09%09%09%09null, %0A%09%09%09%09%22Hello%22,%0A%09%09%09%09null,%0A%09%09%09%09%22World%22);%0A%09%09%0A%09%09String firstNonNull = Iterables.find(strings, Predicates.notNull());%0A%09%09%0A%09%09assertEquals(%22Hello%22, firstNonNull);%0A%09%7D%0A%09%0A%09@Test%0A%09public void find_first_non_null_list_apache () %7B%0A%09%09%0A%09%09List%3CString%3E strings = new ArrayList%3CString%3E();%0A%09%09strings.add(null);%0A%09%09strings.add(%22Hello%22);%0A%09%09strings.add(null);%0A%09%09strings.add(%22World%22);%0A%09%09%0A%09%09String firstNonNull = (String) ObjectUtils.firstNonNull(strings.toArray());%0A%09%09%0A%09%09assertEquals(%22Hello%22, firstNonNull);%0A%09%7D%0A%09%0A%7D%0A

added Find first non null