Example usage for java.util List size

List of usage examples for java.util List size

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of elements in this list.

Usage

From source file:Main.java

public static int getSize(List list) {
    return list == null ? 0 : list.size();
}

From source file:Main.java

public static <T> T tryToGet2ndElement(List<T> list) {
    int size = list.size();
    long id = 0;/*www  .ja v  a2  s.c o  m*/
    if (size < 2) {
        return list.get(0);
    } else {
        return list.get(1);
    }
}

From source file:Main.java

public static boolean isEmptyList(List<?> list) {
    return list == null || list.size() == 0;
}

From source file:Main.java

public static <T> T firstItem(List<T> list) {
    return list != null && list.size() > 0 ? list.get(0) : null;
}

From source file:Main.java

public static boolean emptyList(List<?> list) {
    return (null != list && list.size() <= 0);
}

From source file:Main.java

public static <E> boolean isSublistOf(List<E> bigger, List<E> smaller) {
    if (smaller.size() > bigger.size()) {
        return false;
    }/*from   w  ww .  j ava 2s .co  m*/
    for (int start = 0; start + smaller.size() <= bigger.size(); ++start) {
        List<E> sublist = bigger.subList(start, start + smaller.size());
        if (sublist.equals(bigger)) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static long[] LongListtolongArray(List<Long> LongList) {
    int s = LongList.size();
    long[] ret = new long[s];
    for (int i = 0; i < s; i++) {
        ret[i] = LongList.get(i);//from www.jav  a 2s  .  c o  m
    }
    return ret;
}

From source file:Main.java

public static <T> List<T> subList(List<T> target, int size) {
    if (target.size() <= size) {
        return new ArrayList<T>(target);
    } else {//from w  w  w . j a v a  2s.c o  m
        return target.subList(0, size);
    }
}

From source file:Main.java

public static <T> List<T> head(List<T> list, int n) {
    if (n <= list.size()) {
        return list.subList(0, n);
    } else {/* w w w. j  a va2s.c  o  m*/
        return list;
    }
}

From source file:Main.java

public static <T> int getCount(List<T> list) {
    return list == null ? 0 : list.size();
}