List of usage examples for java.util List get
E get(int index);
From source file:Main.java
public static byte[] list2buffer(List<Byte> list) { byte[] buffer = new byte[list.size()]; for (int i = 0; i < list.size(); i++) { buffer[i] = list.get(i); }//from w ww . j a v a 2 s . co m return buffer; }
From source file:Main.java
public static int[] toPrimitiveInt(List<Integer> list) { int[] array = new int[list.size()]; for (int i = 0; i < list.size(); i++) { array[i] = list.get(i); }/*from w w w . ja v a 2 s . c o m*/ return array; }
From source file:com.us.test.H2Helper.java
/** * IP//from w w w . j a v a 2s . c o m */ private static String ip2Long(String str) { List<Long> ary = StringUtil.splitKillNull(str, "\\."); long l = 0; l += ary.get(0) * 256l * 256l * 256l; l += ary.get(1) * 256l * 256l; l += ary.get(2) * 256l; l += ary.get(3); return Long.toString(l); }
From source file:Main.java
/** * Returns the last element of the collection. * /*from ww w. j ava2 s. co m*/ * @param <T> * the element type * @param iterable * the collection * @return the last element or null if the list is empty */ public static <T> T last(Iterable<T> iterable) { if (iterable instanceof Deque<?>) return ((Deque<T>) iterable).getLast(); if (iterable instanceof List<?>) { List<T> list = (List<T>) iterable; return list.isEmpty() ? null : list.get(list.size() - 1); } Iterator<T> iterator = iterable.iterator(); T last = null; while (iterator.hasNext()) last = iterator.next(); return last; }
From source file:Main.java
public static final Element getChildElement(Element parent) throws IOException { final List<Element> childElements = getChildElements(parent); if (childElements.size() == 1) { return childElements.get(0); } else {/* w w w. j a v a 2 s .c o m*/ throw new IOException("Expected one child element"); } }
From source file:Main.java
public static ResolveInfo getResolveInfo(PackageManager pm, String packageName) { Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setPackage(packageName);/*from w ww . ja v a 2 s . co m*/ List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0); if (apps != null && apps.size() > 0) { return apps.get(0); } return null; }
From source file:Main.java
/** * Helper method to format a list of names. * @param names The list of names//from w w w . j a v a 2 s . co m */ public static String formatNames(List<String> names) { if (names == null || names.size() == 0) return ""; String namesListString = names.get(0); for (int i = 1; i < names.size(); i++) { namesListString += ", " + names.get(i); } return namesListString; }
From source file:Main.java
public static <T extends Object> T[] toArray(List<T> list) { if (list == null || list.isEmpty()) return null; T[] array = (T[]) Array.newInstance(list.get(0).getClass(), list.size()); for (int i = 0; i < array.length; i++) array[i] = list.get(i);// www . j a va 2 s . c o m return array; }
From source file:Main.java
public static <A> List<A> iterateCorecursive(A seed, Function<A, A> fun, Integer n) { List<A> acc = new ArrayList<>(n); acc.add(seed);/* w w w. ja va 2s . c om*/ for (int count = 0; count < n - 1; ++count) { A last = acc.get(count); acc.add(fun.apply(last)); } return acc; }
From source file:Main.java
static <T extends Comparable<T>> void nthElement(int start, int n, int end, List<T> list) { List<T> newList = new ArrayList<T>(); for (int i = start; i < end; i++) newList.add(list.get(i)); Collections.sort(newList);/*from ww w . ja v a 2s . c om*/ for (int i = start, j = 0; i < end; i++, j++) list.set(i, newList.get(j)); }