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 void revokePermission(String packageName, String permission, Context ctx) {
    String[] rPerms = getRevokedPerms(packageName, ctx);
    if (rPerms == null)
        rPerms = new String[0];
    ArrayList<String> revokedPerms = new ArrayList<String>();
    revokedPerms.addAll(Arrays.asList(rPerms));

    if (!revokedPerms.contains(permission)) {
        revokedPerms.add(permission);/*from ww  w.  j a  v  a  2 s . co  m*/
        String[] permsToRevoke = new String[revokedPerms.size()];
        revokedPerms.toArray(permsToRevoke);
        setRevokedPermissions(packageName, permsToRevoke, ctx);
    }
}

From source file:Main.java

public static void getTop(ArrayList<Double> array, ArrayList<Integer> rankList, int i) {
    int index = 0;
    HashSet<Integer> scanned = new HashSet<Integer>();
    Double max = Double.MIN_VALUE;
    for (int m = 0; m < i && m < array.size(); m++) {
        max = Double.MIN_VALUE;//  w  w  w .j a v  a  2s  .  c  o m
        for (int no = 0; no < array.size(); no++) {
            if (!scanned.contains(no)) {
                if (array.get(no) > max) {
                    index = no;
                    max = array.get(no);
                } else if (array.get(no).equals(max) && Math.random() > 0.5) {
                    index = no;
                    max = array.get(no);
                }
            }
        }
        if (!scanned.contains(index)) {
            scanned.add(index);
            rankList.add(index);
        }
        //System.out.println(m + "\t" + index);
    }
}

From source file:cn.sharesdk.analysis.db.MessageUtils.java

/**
 * delect msg by id//from   ww w.j  a v  a 2s.c o m
 * @param c
 * @param id
 * @return
 */
public static synchronized long deleteManyMsg(Context c, ArrayList<String> idList) {
    StringBuilder buider = new StringBuilder();
    for (int i = 0; i < idList.size(); i++) {
        buider.append("'");
        buider.append(idList.get(i));
        buider.append("'");
        buider.append(",");
    }
    String list = buider.toString().substring(0, buider.length() - 1);

    DBProvider provider = DBProvider.getDBProvider(c);
    int deleteCount = provider.delete(DBHelp.TABLE_STATISTICS, DBHelp.COLUMN_ID + " in ( " + list + " )", null);
    //Ln.e("delete COUNT == %s", deleteCount);   
    return deleteCount;
}

From source file:Main.java

public static File[] getFilesDirectorio(String nombreDirectorio) {
    File directorio = new File(nombreDirectorio);
    File[] files = directorio.listFiles();
    ArrayList<File> filtro = new ArrayList<File>();
    if (files != null)
        for (int i = 0; i < files.length; i++) {
            if (files[i].isFile()) {
                filtro.add(files[i]);//from   w  w w .j  a  v  a 2  s  . co  m
            }
        }
    return filtro.toArray(new File[filtro.size()]);
}

From source file:Main.java

/**
 * Convert a list of Strings from an Interator into an array of Classes (the
 * Strings are taken as classnames)./*from   ww  w  . j a va 2 s.  c o m*/
 * 
 * @param it
 *          A java.util.Iterator pointing to a Collection of Strings
 * @param cl
 *          The ClassLoader to use
 * 
 * @return Array of Classes
 * 
 * @throws ClassNotFoundException
 *           When a class could not be loaded from the specified ClassLoader
 */
public final static Class<?>[] convertToJavaClasses(Iterator<String> it, ClassLoader cl)
        throws ClassNotFoundException {
    ArrayList<Class<?>> classes = new ArrayList<Class<?>>();
    while (it.hasNext()) {
        classes.add(convertToJavaClass(it.next(), cl));
    }
    return classes.toArray(new Class[classes.size()]);
}

From source file:Main.java

public static List<ByteBuffer> mergeAdjacentBuffers(List<ByteBuffer> paramList) {
    ArrayList localArrayList = new ArrayList(paramList.size());
    Iterator localIterator = paramList.iterator();
    while (localIterator.hasNext()) {
        ByteBuffer localByteBuffer1 = (ByteBuffer) localIterator.next();
        int i = -1 + localArrayList.size();
        if ((i >= 0) && (localByteBuffer1.hasArray()) && (((ByteBuffer) localArrayList.get(i)).hasArray())
                && (localByteBuffer1.array() == ((ByteBuffer) localArrayList.get(i)).array())
                && (((ByteBuffer) localArrayList.get(i)).arrayOffset()
                        + ((ByteBuffer) localArrayList.get(i)).limit() == localByteBuffer1.arrayOffset())) {
            ByteBuffer localByteBuffer3 = (ByteBuffer) localArrayList.remove(i);
            localArrayList.add(ByteBuffer.wrap(localByteBuffer1.array(), localByteBuffer3.arrayOffset(),
                    localByteBuffer3.limit() + localByteBuffer1.limit()).slice());
        } else if ((i >= 0) && ((localByteBuffer1 instanceof MappedByteBuffer))
                && ((localArrayList.get(i) instanceof MappedByteBuffer))
                && (((ByteBuffer) localArrayList.get(i))
                        .limit() == ((ByteBuffer) localArrayList.get(i)).capacity()
                                - localByteBuffer1.capacity())) {
            ByteBuffer localByteBuffer2 = (ByteBuffer) localArrayList.get(i);
            localByteBuffer2.limit(localByteBuffer1.limit() + localByteBuffer2.limit());
        } else {/*from   w  w  w. j a v  a2s.c  o  m*/
            localByteBuffer1.reset();
            localArrayList.add(localByteBuffer1);
        }
    }
    return localArrayList;
}

From source file:Main.java

static String[] removeWithspaces(String[] values) {
    ArrayList<String> list = new ArrayList<String>(values.length);
    for (int i = 0; i < values.length; i++) {
        if (!values[i].equals("") && !values[i].equals(" ") && !values[i].equals("\t"))
            list.add(values[i]);//from w  w w  . jav a  2s.c  o  m
    }
    return list.toArray(new String[list.size()]);
}

From source file:org.neo4j.nlp.examples.wikipedia.main.java

private static List<Map<String, Object>> getWikipediaArticles() throws IOException {
    final String txUri = "http://localhost:7474/db/data/" + "transaction/commit";
    WebResource resource = Client.create().resource(txUri);

    String query = "MATCH (n:Page) WITH n, rand() as sortOrder " + "ORDER BY sortOrder " + "LIMIT 1000 "
            + "RETURN n.title as title";

    String payload = "{\"statements\" : [ {\"statement\" : \"" + query + "\"} ]}";
    ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON)
            .entity(payload).post(ClientResponse.class);

    ObjectMapper objectMapper = new ObjectMapper();
    HashMap<String, Object> result;
    try {/*from   ww  w  .j a  v a  2s .c  om*/
        result = objectMapper.readValue(response.getEntity(String.class), HashMap.class);
    } catch (Exception e) {
        throw e;
    }
    response.close();

    List<Map<String, Object>> results = new ArrayList<>();

    ArrayList resultSet = ((ArrayList) result.get("results"));
    List<LinkedHashMap<String, Object>> dataSet = (List<LinkedHashMap<String, Object>>) resultSet.stream()
            .map(a -> (LinkedHashMap<String, Object>) a).collect(Collectors.toList());

    List<LinkedHashMap> rows = (List<LinkedHashMap>) ((ArrayList) (dataSet.get(0).get("data"))).stream()
            .map(m -> (LinkedHashMap) m).collect(Collectors.toList());
    ArrayList cols = (ArrayList) (dataSet.get(0).get("columns"));

    for (LinkedHashMap row : rows) {
        ArrayList values = (ArrayList) row.get("row");
        Map<String, Object> resultRecord = new HashMap<>();
        for (int i = 0; i < values.size(); i++) {
            resultRecord.put(cols.get(i).toString(), values.get(i));
        }
        results.add(resultRecord);
    }
    return results;
}

From source file:com.baidu.cafe.local.NetworkUtils.java

/**
 * invoked 100 times costs 4800ms on Nexus One
 * /*from   w w w . j  av a 2 s.c  om*/
 * @param packageName
 * @param mode
 * @return
 */
private static int getPackageTraffic(String packageName, String mode) {
    if ((!MODE_RCV.equals(mode)) && (!MODE_SND.equals(mode))) {
        print("mode invaild:" + mode);
        return -1;
    }

    int traffic = 0;
    ArrayList<Integer> pids = getPidsByPackageName(packageName);
    if (pids.size() < 1) {
        print("pids.size() < 1;get pids by [" + packageName + "] failed");
        return -1;
    }
    int pid = pids.get(0);

    if (Build.VERSION.SDK_INT >= 14) {// API Level: 14. Android 4.0
        int uid = getUidByPid(pid);
        if (-1 == uid) {
            print("-1 == uid");
            return -1;
        }
        ArrayList<String> ret = new ShellExecute().execute(String.format("cat /proc/uid_stat/%s/%s", uid, mode),
                "/").console.strings;
        if (ret.size() > 0) {
            traffic = Integer.valueOf(ret.get(0));
        } else {
            print(String.format("Failed: cat /proc/uid_stat/%s/%s", uid, mode));
        }
    } else {
        Strings netString = new ShellExecute().execute(String.format("cat /proc/%s/net/dev", pid), "/").console;
        int rcv = 0;
        int snd = 0;
        for (String networkCard : NETWORK_CARD_TYPES) {
            Strings netLine = netString.grep(networkCard);
            if (netLine.strings.size() != 1) {
                continue;
            }
            rcv += Integer.valueOf(netLine.getRow("\\s{1,}", 2).strings.get(0));
            snd += Integer.valueOf(netLine.getRow("\\s{1,}", 10).strings.get(0));
        }
        if (MODE_RCV.equals(mode)) {
            traffic = rcv;
        } else if (MODE_SND.equals(mode)) {
            traffic = snd;
        }
    }
    return traffic;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <E> E[] toArray(Collection<?> collection, Class<E> elementType, boolean sort) {
    if (collection == null || collection.isEmpty())
        return null;
    ArrayList arraylist = new ArrayList(collection);
    if (sort) {// ww  w. j  a v a  2 s  . c o  m
        Collections.sort(arraylist);
    }

    E[] array = (E[]) Array.newInstance(elementType, arraylist.size());
    arraylist.toArray(array);
    return array;
}