List of usage examples for java.util List get
E get(int index);
From source file:Main.java
public static String getSingleNodeTextContent(Node node, String path) { List nodeList = getNodes(node, path); if ((nodeList.size() > 0) && (nodeList.get(0) != null) && (((Node) nodeList.get(0)).getTextContent().length() > 0)) { return ((Node) nodeList.get(0)).getTextContent(); }// ww w . jav a 2 s . co m return null; }
From source file:Main.java
public static Double getMaxElement(List<Double> list) { Double max = -1000d;/*from w ww .j a v a2s. co m*/ for (int i = 0; i < list.size(); i++) { if (list.get(i).compareTo(max) > 0) { max = list.get(i); } } return max; }
From source file:Main.java
/** * Random parameter returns random item from list. * /* ww w.j av a 2 s .co 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> T getLast(List<T> list) { if (isEmpty(list)) { return null; }//www . j a va 2s . co m return list.get(list.size() - 1); }
From source file:Main.java
/** * exception safe access of an element of a list by index. * * @param list// w w w.j av a 2 s . c om * @param index * @return null if the index is out of the list bounds or the element is null by itself. */ public static <T> T getElement(List<T> list, int index) { if (index >= 0 && index < list.size()) { return list.get(index); } return null; }
From source file:Main.java
private static <T> T get(List<T> list, int index) { if (list.size() <= index) return null; return list.get(index); }
From source file:Main.java
public static double position(String s, List<String> ss) { double p = -1d; for (int i = 0; i < ss.size(); i++) { if (s.equals(ss.get(i))) { p = Double.parseDouble(i + ""); break; }//from w w w . j ava 2 s .c om } return p; }
From source file:Main.java
/** * Determines if the given list is sorted (in ascending order). * @param list The <code>List</code> to examine. * @return A value indciating whether the list is sorted in ascending * order.//from ww w .ja v a 2 s . co m */ public static <T extends Comparable<? super T>> boolean isSorted(List<T> list) { for (int i = 1, n = list.size(); i < n; i++) { if (list.get(i - 1).compareTo(list.get(i)) > 0) { return false; } } return true; }
From source file:Main.java
/** * Get Value at Index or default value./*ww w . jav a 2s. co m*/ * @param <T> T * @param list {@link List} * @param index int * @param defaultValue default value * @return T return value */ public static <T> T get(final List<T> list, final int index, final T defaultValue) { try { return list.get(index); } catch (IndexOutOfBoundsException e) { return defaultValue; } }
From source file:Main.java
public static <T> T getLastOrNull(List<T> l) { final int size = l.size(); if (size == 0) return null; return l.get(size - 1); }