List of usage examples for java.util ArrayList size
int size
To view the source code for java.util ArrayList size.
Click Source Link
From source file:Main.java
/** * Merge two ascending/descending array and keep the first n elements. * @param ascending/*from w w w . j av a 2 s .c om*/ * if true, the array is sorted in ascending order, * otherwise it is in descending order. */ static <T extends Comparable<T>> ArrayList<T> sortedMerge(List<T> a1, List<T> a2, boolean ascending, int n) { Comparator<T> comparator = getComparator(ascending, (T) null); int n1 = a1.size(); int n2 = a2.size(); int p1 = 0; // The current element in a1 int p2 = 0; // The current element in a2 ArrayList<T> output = new ArrayList<T>(n); while (output.size() < n && (p1 < n1 || p2 < n2)) { if (p1 < n1) { if (p2 == n2 || comparator.compare(a1.get(p1), a2.get(p2)) < 0) { output.add(a1.get(p1++)); } } if (output.size() == n) { break; } if (p2 < n2) { if (p1 == n1 || comparator.compare(a2.get(p2), a1.get(p1)) < 0) { output.add(a2.get(p2++)); } } } return output; }
From source file:fr.bmartel.android.notti.service.bluetooth.events.BluetoothObject.java
public static BluetoothObject parseArrayList(Intent intent) { ArrayList<String> actionsStr = intent.getStringArrayListExtra(""); if (actionsStr.size() > 0) { try {/* w ww . j a v a 2s . co m*/ JSONObject mainObject = new JSONObject(actionsStr.get(0)); if (mainObject.has(BluetoothConst.DEVICE_ADDRESS) && mainObject.has(BluetoothConst.DEVICE_NAME)) { return new BluetoothObject(mainObject.get(BluetoothConst.DEVICE_ADDRESS).toString(), mainObject.get(BluetoothConst.DEVICE_NAME).toString()); } } catch (JSONException e) { e.printStackTrace(); } } return null; }
From source file:Main.java
/** * Method to join array elements of type string * /*from ww w. j av a2 s. c om*/ * @param input * Array which contains strings * @param glue * String between each array element * @return String containing all array elements separated by glue string */ public static String implode(ArrayList<String> list, String glue) { String[] input = new String[list.size()]; for (int i = 0; i < list.size(); i++) { input[i] = list.get(i); } return implode(input, glue); }
From source file:Main.java
public static ArrayList<Integer> getRandomNumbers(int range, int count, Random rnd) { if (count > range) { return null; }// w w w.j a v a2s .com if (count < 0 || range < 0) { return null; } HashMap<Integer, Integer> used = new HashMap<Integer, Integer>(); ArrayList<Integer> indices = new ArrayList<Integer>(); int n = range; while (indices.size() < count) { Integer r = Integer.valueOf(rnd.nextInt(n)); if (used.containsKey(r)) { indices.add(used.get(r)); } else { indices.add(r); } addToUsed(used, r, n - 1); n--; } return indices; }
From source file:Main.java
public static byte[] toBytes(ArrayList<Byte> data) { byte[] rval = new byte[data.size()]; for (int i = 0; i < data.size(); i++) { rval[i] = data.get(i);//w w w . j ava 2 s .c o m } return rval; }
From source file:Main.java
private static void verifyArrayListIsSingleType(ArrayList arrayList) { for (int i = 1; i < arrayList.size(); i++) { if (!arrayList.get(i - 1).getClass().isInstance(arrayList.get(i))) { throw new IllegalArgumentException("Cannot pass array of multiple types via props"); }/*w w w .ja va 2 s. com*/ } }
From source file:Main.java
public final static <T> void add(ArrayList<T> origin, ArrayList<T> list) { if (origin == null) { throw new IllegalArgumentException(""); }// ww w. jav a 2 s .co m if (list == null || list.size() == 0) { return; } origin.addAll(list); }
From source file:Main.java
/** * gets the first value on the first AL that is equal to another in the second * /* ww w .j a v a 2 s .c o m*/ * @param alFirst * @param alSecond * @return the string value equal between the two AL, or null if such value doesn't exist */ public static String getFirstSameValue(ArrayList<String> alFirst, ArrayList<String> alSecond) { // cycles of the first AL for (int j = 0; j < alFirst.size(); j++) { // gets the j-th value String strValue = alFirst.get(j); // cycles of the second AL for (int i = 0; i < alSecond.size(); i++) { // if the two values are equal, return the value if (strValue.equals(alSecond.get(i))) return strValue; } } // hasn't found nothing, so returns null return null; }
From source file:Main.java
/** * Returns true if the two ArrayLists are equal with respect to the objects they contain. * The objects must be in the same order and be reference equal (== not .equals()). *//* ww w . j a v a 2 s .c o m*/ public static <T> boolean referenceEquals(ArrayList<T> a, ArrayList<T> b) { if (a == b) { return true; } final int sizeA = a.size(); final int sizeB = b.size(); if (a == null || b == null || sizeA != sizeB) { return false; } boolean diff = false; for (int i = 0; i < sizeA && !diff; i++) { diff |= a.get(i) != b.get(i); } return !diff; }
From source file:Main.java
/** * Render a path by actually drawing line segments instead. When using a real {@link Path}, then it is first painted * into a temporary bitmap by the CPU, before being rendered by the GPU. That simply fails for large paths, * therefore we use a synthesis from line segments, since lines are drawn entirely by the GPU. */// www . ja v a2 s . c o m public static void drawPath(final ArrayList<Point> pixelPoints, final Canvas canvas, final Paint paint) { final float[] pointData = new float[(pixelPoints.size() - 1) * 4]; for (int i = 1; i < pixelPoints.size(); i++) { final Point last = pixelPoints.get(i - 1); final Point current = pixelPoints.get(i); final int index = (i - 1) * 4; // start point pointData[index] = last.x; pointData[index + 1] = last.y; // end point pointData[index + 2] = current.x; pointData[index + 3] = current.y; } canvas.drawLines(pointData, paint); }