Example usage for java.util List isEmpty

List of usage examples for java.util List isEmpty

Introduction

In this page you can find the example usage for java.util List isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:Main.java

public static <T> boolean isEmpty(List<T> list) {
    return list == null || list.isEmpty();
}

From source file:Main.java

public static boolean isEmpty(List photos) {
    return !(photos != null && photos.isEmpty());
}

From source file:Main.java

/**
 * Random parameter returns random item from list.
 * //from w  ww .j  a v  a  2  s  .c o  m
 * @param <E>
 *            Class for list where you get random item.
 * @param e
 *            A random parameter for the array.
 * @return A random item from a list.
 */
public static <E> E randomItem(List<E> e) {
    if (e.isEmpty()) {
        return null;
    }
    return e.get(RANDOM.nextInt(e.size()));
}

From source file:Main.java

public static <T> boolean isEmpty(List<T> list) {
    if (list == null || list.isEmpty()) {
        return true;
    }//from www. j  av  a 2  s.c  o m

    return false;
}

From source file:Main.java

public static boolean isBlank(List list) {
    return (list == null || list.isEmpty());
}

From source file:Main.java

/** Returns the last element in list or <code>null</code>, if list is empty. */
@SuppressWarnings("unchecked")
public static <T> T getLast(List<T> list) {
    if (list.isEmpty()) {
        return null;
    }/*ww  w .jav a2  s.  com*/
    if (list instanceof Deque<?>) {
        return ((Deque<T>) list).getLast();
    }
    return list.get(list.size() - 1);
}

From source file:Main.java

public static <T extends Object> T[] toArray(List<T> list) {
    if (list == null || list.isEmpty())
        return null;

    T[] array = (T[]) Array.newInstance(list.get(0).getClass(), list.size());
    for (int i = 0; i < array.length; i++)
        array[i] = list.get(i);/*  w ww  .  j a  v a2 s .  c o  m*/
    return array;
}

From source file:Main.java

private static boolean checkNotEmpty(List list) {
    return list != null && !list.isEmpty();
}

From source file:Main.java

/**
 * /*from w  ww  .ja  v  a  2  s .  com*/
 * @param <T>
 * @param list
 */
public static <T> void filterNulls(List<T> list) {
    if (null == list || list.isEmpty())
        return;
    for (int i = 0; i < list.size(); i++) {
        T current = list.get(i);
        if (null == current) {
            list.remove(i);
        }
    }
}

From source file:Main.java

private static <A> List<A> reverse(List<A> as, List<A> acc) {
    return as.isEmpty() ? acc : reverse(tail(as), cons(head(as), acc));
}