Java List First Item getFirstElement(List list)

Here you can find the source of getFirstElement(List list)

Description

get First Element

License

Apache License

Declaration

public static <T> T getFirstElement(List<? extends T> list) 

Method Source Code

//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;
    }
}

Related

  1. getFirst(List list)
  2. getFirst(List source)
  3. getFirstAsString(Map> multiValueMap, String key)
  4. getFirstColumn(List> llo, String reason)
  5. getFirstDuplicateValue(List values)
  6. getFirstElement(List collection)
  7. getFirstElement(List list)
  8. getFirstElement(List list)
  9. getFirstElementFromList(List list)