List of usage examples for java.util List get
E get(int index);
From source file:Main.java
public static <T> T previous(List<T> items, T t) { int i = items.indexOf(t); return i != -1 ? items.get((i + items.size() - 1) % items.size()) : null; }
From source file:Main.java
public static <T> T getLast(List<T> list) // NO_UCD (unused code) { return isNullOrEmpty(list) ? null : list.get(list.size() - 1); }
From source file:Main.java
/** * Returns an array of aList items in the same order than the {@link List}. * * @param aList// ww w . j a va2 s . c o m * {@link List} to transform. * * @return {@link T[]} array of aList items in the same order than the {@link List}. * * @since 1 */ public static <T> T[] toArray(List<T> aList) { T[] result = (T[]) Array.newInstance(aList.get(0).getClass(), 2); result = aList.toArray(result); return result; }
From source file:Main.java
public static <T> T zeroOrOne(List<? extends T> items) { return items == null || items.isEmpty() ? null : items.get(0); }
From source file:Main.java
static <T extends Comparable<T>> T getNthElement(int n, List<T> list) { List<T> newList = new ArrayList<T>(list); Collections.sort(newList);//from ww w. j av a2 s.c om return newList.get(n); }
From source file:Main.java
/** * Returns first item in the list if list is not empty. * * @param list The list to get first item from. *///from www. j av a2 s .c o m @Nullable public static <T> T first(@Nullable final List<T> list) { return (list == null || list.isEmpty() ? null : list.get(0)); }
From source file:Main.java
public static <V> Object getAdapterItem(List<V> mList, int position) { return (mList == null || position >= mList.size()) ? null : mList.get(position); }
From source file:Main.java
public static <T> T get(Collection<T> c, int index) { if (isEmpty(c)) return null; if (index < 0 || index >= c.size()) return null; if (c instanceof List) return (T) ((List<T>) c).get(index); List<? extends T> a = new ArrayList<T>(c); return a.get(index); }
From source file:Main.java
public static <T> T getOrDefault(List<T> list, int position, @Nullable T defaultValue) { try {//from www.jav a 2 s . co m return list.get(position); } catch (Exception e) { return defaultValue; } }
From source file:Main.java
/** * Returns last item in {@link List}.// ww w. j ava 2 s.co m * @param <T> type * @param t T * @return T */ public static <T> T last(final List<T> t) { return t != null && t.size() > 0 ? t.get(t.size() - 1) : null; }