Java List First Item first(List list)

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

Description

Returns the first element of the passed list, null if the list is empty or null.

License

Apache License

Declaration

public static <T> T first(List<T> list) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.util.Collection;

import java.util.List;

public class Main {
    /**/* w ww. j a v  a2 s. co  m*/
     *  Returns the first element of the passed list, <code>null</code> if
     *  the list is empty or null.
     */
    public static <T> T first(List<T> list) {
        return isNotEmpty(list) ? list.get(0) : null;
    }

    /**
     *  Returns <code>true</code> if the passed collection is not <code>null</code>
     *  and has size &gt; 0.
     */
    public static boolean isNotEmpty(Collection<?> c) {
        return (c != null) && (c.size() > 0);
    }
}

Related

  1. first(List l)
  2. first(List list)
  3. first(List list)
  4. first(List list)
  5. first(List list)
  6. first(List list)
  7. first(List list)
  8. first(List list)
  9. first_nItems(int n, Collection fromList)