Example usage for java.util List get

List of usage examples for java.util List get

Introduction

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

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:Main.java

public static Integer incrementAndGet(List<Integer> list, int index) {
    Integer integer = list.get(index);
    return list.set(index, integer + 1);
}

From source file:com.vaporwarecorp.mirror.util.RandomUtil.java

public static <T> T randomValue(List<T> values) {
    return values.get(RANDOM_GENERATOR.nextInt(values.size()));
}

From source file:Main.java

/**
 * Given a list, returns a random element from that list.
 *
 * @param list  The list to return a random element from
 *
 * @param <T>  The element type of the list
 *
 * @return A random element from the list
 *///from  w ww  .  j av  a2 s .  c o  m
public static <T> T getRandomElement(List<T> list) {
    return list.get(new Random().nextInt(list.size()));
}

From source file:Main.java

public static <T extends Object> T getWithoutRangeCheck(List<T> col, int i) {
    try {//from   ww  w  .  j  a v  a2  s . c  om
        return col.get(i);
    } catch (IndexOutOfBoundsException e) {
        return null;
    }
}

From source file:Main.java

public static <E> E safeGet(List<E> list, int index) {
    return list.size() > index ? list.get(index) : null;
}

From source file:Main.java

public static <O> O safeGet(List<O> l, int index) {
    try {/*www.  ja  v a  2 s  .c o m*/
        return l.get(index);
    } catch (Throwable ex) {
        return null;
    }
}

From source file:Main.java

public static <T> T last(final List<T> c) {
    return isNullOrEmpty(c) ? null : c.get(c.size() - 1);
}

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

/**
 *  Returns the first element of the passed list, <code>null</code> if
 *  the list is empty or null.//from w  w  w  .j av a 2s.c  o m
 */
public static <T> T first(List<T> list) {
    return isNotEmpty(list) ? list.get(0) : null;
}

From source file:Main.java

/**
 * /*from   ww w .  ja v a2 s . c  om*/
 * @param <T>
 * @param list [!list.isEmpty()]
 * @return the last element of the list
 */
public static <T> T getLast(List<T> list) {
    return list.get(list.size() - 1);
}