Here you can find the source of getFirstElement(List extends T> list)
public static <T> T getFirstElement(List<? extends T> list)
//package com.java2s; //License from project: Apache License import java.util.List; public class Main { public static <T> T getFirstElement(List<? extends T> list) { for (int i = 0; i < list.size(); i++) { T obj = list.get(i);// w ww . java 2 s . co m if (obj != null) return obj; } return null; } public static <T> T getFirstElement(T[] array) { for (int i = 0; i < array.length; i++) { if (array[i] != null) return array[i]; } return null; } }