List of usage examples for java.util List get
E get(int index);
From source file:Main.java
private static <T> boolean equlWithoutComparator(List<T> l1, List<T> l2) { final int n1 = l1.size(); for (int i = 0; i < n1; i++) { T e1 = l1.get(i); T e2 = l2.get(i);//www . j a v a 2 s .c o m if (e1 == null) { if (e2 != null) { return false; } } else if (!e1.equals(e2)) { return false; } } return true; }
From source file:Main.java
/** * Returns the first element of the collection. * /* w ww.j av a 2 s. com*/ * @param <T> * the element type * @param iterable * the collection * @return the first element or null if the list is empty */ public static <T> T first(Iterable<T> iterable) { if (iterable instanceof Deque<?>) return ((Deque<T>) iterable).getFirst(); if (iterable instanceof List<?>) { List<T> list = (List<T>) iterable; return list.isEmpty() ? null : list.get(0); } Iterator<T> iterator = iterable.iterator(); return iterator.hasNext() ? iterator.next() : null; }
From source file:Main.java
/** * Determines if all entries in a list are equal. * // w ww. jav a 2s .c o m * @param list * the list to check equal objects. * @return true, if all objects are equal; false otherwise. */ public static <T> boolean allEqual(List<T> list) { boolean allEqual = true; for (int i = 0; i < list.size(); i++) { if (!list.get(0).equals(list.get(i))) { allEqual = false; break; } } return allEqual; }
From source file:Main.java
static public int[] ToInts(List<Integer> list) { int[] ints = new int[list.size()]; for (int i = 0; i < list.size(); i++) { ints[i] = list.get(i); }//from ww w. ja va 2s .c o m return ints; }
From source file:Main.java
/** * Append the given list of children Elements to the given Element. * * @param element The parent element./* w ww.ja v a2 s . com*/ * @param children The list of children. */ public static void addChildren(Element element, List children) { for (int i = 0; i < children.size(); i++) { element.appendChild((Element) children.get(i)); } }
From source file:Main.java
public static boolean judge(List<String> list, String dir) { boolean result = false; for (int i = 0; i < list.size(); i++) { if (list.get(i).equals(dir)) { result = true;//from w ww . j ava 2 s .c o m return result; } } return result; }
From source file:Main.java
public static String getTopActivity(Activity context) { ActivityManager manager = (ActivityManager) context.getSystemService(Activity.ACTIVITY_SERVICE); List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1); if (runningTaskInfos != null) return (runningTaskInfos.get(0).topActivity).getShortClassName(); else//from ww w.j a va 2 s . co m return null; }
From source file:Main.java
public static <T> List<T> limit(List<T> source, int size) { List<T> dest = new ArrayList<>(); for (int i = 0; i < size; i++) { dest.add(source.get(i)); }/*from w w w . ja v a 2s . c o m*/ return dest; }
From source file:Main.java
public static boolean[] toPrimitiveBooleanArray(List<Boolean> list) { boolean[] res = new boolean[list.size()]; for (int i = 0; i < list.size(); i++) res[i] = list.get(i); return res;/*from w w w .j a v a 2 s . c o m*/ }
From source file:org.zht.framework.validate.ValidateHandler.java
public static ValidateResult handle(BindingResult result) { ValidateResult retVal = new ValidateResult(); if (result.hasErrors()) { List<ObjectError> list = result.getAllErrors(); ObjectError oe = list.get(0); retVal.setMessage(oe.getDefaultMessage()); retVal.setResult(false);//from w w w . j a v a 2 s .com } else { retVal.setResult(true); } return retVal; }