List of usage examples for java.util List get
E get(int index);
From source file:Main.java
public static <E> Optional<E> max(List<E> elements, Comparator<E> comparator) { if (elements.size() != 0) { E maxElement = elements.get(0); for (int i = 1; i < elements.size(); i++) { maxElement = comparator.compare(maxElement, elements.get(i)) > 0 ? maxElement : elements.get(i); }//from w ww. j a va 2s . c o m return Optional.of(maxElement); } else return Optional.empty(); }
From source file:Main.java
/** * Returns the first found frame of {@code #findFramesWithIcons()}. <p> Especially for usage in a * <code>JOptionPane#show...Dialog()</code> instead of null. Then in the dialog frame an icon will be displayed that * is different to the Java "coffee cup" icon. * * @return frame or null/* w w w.j a va 2s . c om*/ */ public static Frame findFrameWithIcon() { List<Frame> frames = findFramesWithIcons(); return (frames.isEmpty()) ? null : frames.get(0); }
From source file:Main.java
public static <T> T getFirstElement(List<T> liste) { if (isEmpty(liste)) { return null; } else {//w w w. j av a2s . com return liste.get(0); } }
From source file:Main.java
public static Object[] toArrayOnListOfSameType(List aList) { if (aList.isEmpty()) return new Object[0]; Class type = aList.get(0).getClass(); Object[] sameElementsArray = (Object[]) Array.newInstance(type, aList.size()); return aList.toArray(sameElementsArray); }
From source file:Main.java
public static <T> List<T> reversedView(final List<T> list) { return new AbstractList<T>() { @Override//from ww w .ja va 2 s . co m public T get(int index) { return list.get(list.size() - 1 - index); } @Override public int size() { return list.size(); } }; }
From source file:Main.java
public static float getMedian(List<Float> values) { Collections.sort(values);//from w w w. ja va 2 s. co m if (values.size() % 2 == 0) { return (values.get(values.size() / 2 - 1) + values.get(values.size() / 2)) / 2; } else { return values.get(values.size() / 2); } }
From source file:Main.java
public static String getRandomTAG(List<String> list) { Random random = new Random(); int i = random.nextInt(list.size()); return list.get(i); }
From source file:Main.java
public static <T> T tryToGet2ndElement(List<T> list) { int size = list.size(); long id = 0;//from w ww . j a v a 2 s. c o m if (size < 2) { return list.get(0); } else { return list.get(1); } }
From source file:Main.java
public static void printMapList(List<Map> list) { Map map = null;/*from w w w . j a va2 s. c o m*/ for (int i = 0; i < list.size(); i++) { map = list.get(i); Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); System.out.println(entry.getKey() + ": " + entry.getValue()); } } }
From source file:Main.java
public static Double getMinElement(List<Double> list) { Double min = 10000d;//from w ww .java 2 s. c o m for (int i = 0; i < list.size(); i++) { if (list.get(i).compareTo(min) < 0) { min = list.get(i); } } return min; }