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

/**
 * @return the last element in the list, or empty if the list is empty
 *//* w w w.j a  va  2 s.c  o  m*/
public static <E> Optional<E> last(List<E> list) {
    if (list.isEmpty())
        return Optional.empty();
    return Optional.of(list.get(list.size() - 1));
}

From source file:Main.java

/**
 * Search of first index of growing y./*ww  w.j av  a2s .co m*/
 *
 * @param valPoints Y points, first index is searched from.
 * @return Index of first growing value.
 */
private static int findStartIndex(List<PointF> valPoints) {
    for (int i = 0; i < valPoints.size() - 1; i++) {
        if (valPoints.get(i).y < valPoints.get(i + 1).y) {
            return i;
        }
    }
    return -1;
}

From source file:net.daboross.bukkitdev.skywars.api.Randomation.java

/**
 * Gets a random item in a given list./*from  w  ww . j a  va  2 s .  c o m*/
 *
 * @param <T>  The type of the item and list.
 * @param list The list to get the items from.
 * @return A random item from this list.
 * @throws NullPointerException If list is null.
 */
public static <T> T getRandom(List<T> list) {
    Validate.notNull(list, "List cannot be null");
    return list.get(random.nextInt(list.size()));
}

From source file:exec.examples.IoHelper.java

public static Context readFirstContext(String dir) {
    for (String zip : findAllZips(dir)) {
        List<Context> ctxs = read(zip);
        return ctxs.get(0);
    }//from   w  w w  .  j a  v  a2 s  .c  o m
    return null;
}

From source file:Main.java

public static <T> T getHead(List<T> list) {
    if (list == null || list.isEmpty()) {
        return null;
    }/*from ww w . ja  v a2s .  c  o  m*/
    return list.get(0);
}

From source file:Main.java

public static <T> T getTail(List<T> list) {
    if (list == null || list.isEmpty()) {
        return null;
    }//from   w w w. j av  a2  s.  c  om
    return list.get(list.size() - 1);
}

From source file:com.cloudera.oryx.kmeans.computation.cluster.CentersIndexLoader.java

private static int getDimension(List<Model> models) {
    return ((ClusteringModel) models.get(0)).getClusteringFields().size();
}

From source file:com.shirokumacafe.archetype.common.utilities.RandomData.java

/**
 * list?.//from  w ww  .j ava  2s  . c om
 */
public static <T> T randomOne(List<T> list) {
    Collections.shuffle(list);
    return list.get(0);
}

From source file:Main.java

public static <E> Optional<E> min(List<E> elements, Comparator<E> comparator) {
    if (elements.size() != 0) {
        E minElement = elements.get(0);
        for (int i = 1; i < elements.size(); i++) {
            minElement = comparator.compare(minElement, elements.get(i)) < 0 ? minElement : elements.get(i);
        }/*www  .jav  a 2s  . c  o m*/
        return Optional.of(minElement);
    } else
        return Optional.empty();
}

From source file:Main.java

public static <T> T getFirst(Map<String, List<T>> multiValutMap, String key) {
    List<T> values = multiValutMap.get(key);
    if (values != null && !values.isEmpty())
        return values.get(0);
    return null;/*  w  w w.j  ava2  s.  c om*/
}