Example usage for java.util ArrayList size

List of usage examples for java.util ArrayList size

Introduction

In this page you can find the example usage for java.util ArrayList size.

Prototype

int size

To view the source code for java.util ArrayList size.

Click Source Link

Document

The size of the ArrayList (the number of elements it contains).

Usage

From source file:Main.java

public static boolean serviceIsWorking(Context context, Class<?> clazz) {
    ActivityManager myManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    ArrayList<RunningServiceInfo> runningService = (ArrayList<RunningServiceInfo>) myManager
            .getRunningServices(30);//  w ww .j  av  a  2s  .c o m
    for (int i = 0; i < runningService.size(); i++) {
        if (runningService.get(i).service.getClassName().toString().equals(clazz.getName())) {// "pr.android.taojia.service.MsgService"
            return true;
        }
    }
    return false;
}

From source file:Main.java

private static double[] toDoubleArray(ArrayList<Double> arrayList) {
    double[] ret = new double[arrayList.size()];
    for (int i = 0; i < ret.length; i++) {
        ret[i] = arrayList.get(i);//w  w  w .j a  v  a2s .c  o m
    }
    return ret;
}

From source file:Main.java

private static List<Object> recursiveAggregateTree(List<Object> items, int maxPerList) {
    if (items.size() > maxPerList) {
        ArrayList<Object> aggregateList = new ArrayList<Object>(maxPerList);
        ArrayList<Object> childList = null;

        for (Object item : items) {
            if (childList == null || childList.size() == maxPerList) {
                childList = new ArrayList<Object>(maxPerList);
                aggregateList.add(childList);
            }/* w  w  w.ja  v  a2s.  c  o  m*/
            childList.add(item);
        }
        if (childList != null) {
            childList.trimToSize();
        }

        aggregateList.addAll(recursiveAggregateTree(aggregateList, maxPerList));

        aggregateList.trimToSize();

        return aggregateList;
    } else {
        // This is a safe blind cast since only subsequent calls of this method will end up here
        // and this method always uses ArrayList<Object>
        return items;
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
private static Bundle[] toBundleArray(ArrayList<HashMap> arrayList) {
    Bundle[] ret = new Bundle[arrayList.size()];
    for (int i = 0; i < ret.length; i++) {
        ret[i] = addMapToBundle(arrayList.get(i), new Bundle());
    }/*  ww w. ja v a 2  s.  c o  m*/
    return ret;
}

From source file:Main.java

public static void setAllCapsInputFilter(EditText et) {
    InputFilter[] prefFilters;/* ww w.  j  a  v  a 2  s  .  co  m*/
    prefFilters = et.getFilters();
    ArrayList<InputFilter> filters = new ArrayList<>(Arrays.asList(prefFilters));
    filters.add(new InputFilter.AllCaps());
    prefFilters = new InputFilter[filters.size()];
    filters.toArray(prefFilters);
    et.setFilters(prefFilters);
}

From source file:Main.java

/**
 * Create a message from an array, first field of the message is the size of the array
 * @param array/*from   w ww  .jav  a2 s  . co m*/
 * @return
 */
public static byte[] createMessageFromArray(ArrayList<byte[]> array) {

    byte[] buffer1 = new byte[4];
    System.arraycopy(ByteBuffer.allocate(4).putInt(array.size()).array(), 0, buffer1, 0, 4);

    byte[] buffer2 = compileMessages(array);

    return concatenateMessages(buffer1, buffer2);
}

From source file:com.github.akinaru.bleanalyzer.bluetooth.events.BluetoothObject.java

public static BluetoothObject parseArrayList(Intent intent) {

    ArrayList<String> actionsStr = intent.getStringArrayListExtra("");

    if (actionsStr.size() > 0) {

        try {/*from ww  w  .  j  a  v a 2  s  . c  o  m*/

            JSONObject mainObject = new JSONObject(actionsStr.get(0));

            if (mainObject.has(JsonConstants.BT_ADDRESS) && mainObject.has(JsonConstants.BT_DEVICE_NAME)) {

                int scanInterval = -1;
                if (mainObject.has(JsonConstants.BT_ADVERTISING_INTERVAL))
                    scanInterval = mainObject.getInt(JsonConstants.BT_ADVERTISING_INTERVAL);

                return new BluetoothObject(mainObject.get(JsonConstants.BT_ADDRESS).toString(),
                        mainObject.get(JsonConstants.BT_DEVICE_NAME).toString(), scanInterval);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:Main.java

public static String arrayListToString(ArrayList<String> stringList, String split) {
    StringBuilder builder = new StringBuilder();
    if (null != stringList) {
        for (int i = 0; i < stringList.size(); i++) {
            builder.append(stringList.get(i).trim());
            if (i < stringList.size() - 1) {
                builder.append(split);/*from   w ww.  j  ava 2s. c o  m*/
            }
        }
    }
    return builder.toString();
}

From source file:Main.java

@SuppressWarnings("unchecked")
private static void putArray(String key, ArrayList arrayList, Bundle bundle) {
    if (arrayList.size() == 0) {
        bundle.putBooleanArray(key, new boolean[] {});
    } else {//  w w w  .ja  v  a2s.  co m
        verifyArrayListIsSingleType(arrayList);
        if (arrayList.get(0) instanceof String) {
            bundle.putStringArray(key, toStringArray((ArrayList<String>) arrayList));
        } else if (arrayList.get(0) instanceof Integer) {
            bundle.putIntArray(key, toIntArray((ArrayList<Integer>) arrayList));
        } else if (arrayList.get(0) instanceof Float) {
            bundle.putFloatArray(key, toFloatArray((ArrayList<Float>) arrayList));
        } else if (arrayList.get(0) instanceof Double) {
            bundle.putDoubleArray(key, toDoubleArray((ArrayList<Double>) arrayList));
        } else if (arrayList.get(0) instanceof Boolean) {
            bundle.putBooleanArray(key, toBooleanArray((ArrayList<Boolean>) arrayList));
        } else if (arrayList.get(0) instanceof HashMap) {
            bundle.putParcelableArray(key, toBundleArray((ArrayList<HashMap>) arrayList));
        } else if (arrayList.get(0) instanceof ArrayList) {
            Log.w("RNNavigation",
                    "Arrays of arrays passed in props are converted to dictionaries with indexes as keys");
            Bundle innerArray = new Bundle();
            for (int i = 0; i < arrayList.size(); i++) {
                putArray(String.valueOf(i), (ArrayList) arrayList.get(i), innerArray);
            }
            bundle.putParcelable(key, innerArray);
        }
    }
}

From source file:Main.java

private static List<Object> recursiveAggregateTree(List<Object> items, int maxPerList) {
    if (items.size() > maxPerList) {
        ArrayList<Object> aggregateList = new ArrayList<Object>(maxPerList);
        ArrayList<Object> childList = null;

        for (Object item : items) {
            if (childList == null || childList.size() == maxPerList) {
                childList = new ArrayList<Object>(maxPerList);
                aggregateList.add(childList);
            }// w w  w .j av  a  2  s  .  co m
            childList.add(item);
        }
        childList.trimToSize();

        aggregateList.addAll(recursiveAggregateTree(aggregateList, maxPerList));

        aggregateList.trimToSize();

        return aggregateList;
    } else {
        // This is a safe blind cast since only subsequent calls of this method will end up here
        // and this method always uses ArrayList<Object>
        return items;
    }
}