List of usage examples for java.util List get
E get(int index);
From source file:Main.java
public static Node xPathEvalSingleNode(String content, String expression) throws XPathExpressionException { List<Node> lst = xPathEvalListNodes(content, expression); if (lst.size() > 0) return lst.get(0); return null;//from ww w . ja v a 2s. com }
From source file:Main.java
public static <T> T firstElement(List<T> c) { if (isEmpty(c)) { return null; }//from ww w .j ava 2s .c o m return c.get(0); }
From source file:Main.java
public static byte[] toByteArray(List<Byte> list) { byte[] ret = new byte[list.size()]; for (int i = 0; i < ret.length; i++) ret[i] = list.get(i); return ret;/* ww w . ja v a 2s .com*/ }
From source file:Main.java
public static Element getChildElement(Element parent, String tagName) { List children = getChildElements(parent, tagName); return children.isEmpty() ? null : (Element) children.get(0); }
From source file:Main.java
public static <T> List<T> indexedSelection(List<T> in, int... indices) { ArrayList<T> res = new ArrayList<T>(); for (int i : indices) res.add(in.get(i)); return res;/*ww w. j ava2 s . co m*/ }
From source file:Main.java
public static <O> O getRandom(final Collection<O> pObjects) { if (pObjects != null && !pObjects.isEmpty()) { int r = Math.abs(random.nextInt() % pObjects.size()); List<O> objects = !(pObjects instanceof List) ? new ArrayList<O>(pObjects) : (List<O>) pObjects; return objects.get(r); }/* ww w. j ava2 s. c o m*/ return null; }
From source file:Main.java
public static long[] toArray(List<Long> list) { long[] n = new long[list.size()]; for (int i = 0; i < list.size(); i++) { n[i] = list.get(i); }/*from w w w . j a va 2 s. c om*/ return n; }
From source file:Main.java
public static Map<String, Object> findFirstVisibleElement(List<HashMap<String, Object>> elements) { //TODO: Should do something more intelligent return (Map<String, Object>) elements.get(0); }
From source file:Main.java
public static String getTopActivity2(Context ctx) { ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); Log.d("topActivity", "CURRENT Activity ::" + taskInfo.get(0).topActivity.getClassName()); ComponentName componentInfo = taskInfo.get(0).topActivity; return componentInfo.getPackageName(); }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T[] listToArray(List<T> list) { if (list == null) { return null; }//from w w w . j ava 2 s . co m T[] tArr = (T[]) Array.newInstance(list.get(0).getClass(), list.size()); return list.toArray(tArr); }