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:mlflex.helper.MathUtilities.java

/** Identifies the quartiles in a list of numbers.
 *
 * @param values Values to be tested/*from   w w  w.ja  v a 2 s .com*/
 * @return An array with the lower quartile, median, and upper quartile
 * @throws Exception
 */
public static double[] Quartiles(ArrayList<Double> values) throws Exception {
    if (values.size() < 3)
        throw new Exception("This method is not designed to handle lists with fewer than 3 elements.");

    double median = Median(values);

    ArrayList<Double> lowerHalf = ListUtilities.LessThan(values, median, true);
    ArrayList<Double> upperHalf = ListUtilities.GreaterThan(values, median, true);

    return new double[] { Median(lowerHalf), median, Median(upperHalf) };
}

From source file:Main.java

/**
 * Access all immediate child elements inside the given Element
 *
 * @param element the starting element, cannot be null.
 * @param elemName the name of the child element to look for, cannot be
 * null.//from   www . jav a 2  s  .co m
 * @return array of all immediate child element inside element, or
 * an array of size zero if no child elements are found.
 */
public static Element[] getChildElements(Element element) {
    NodeList list = element.getChildNodes();
    int len = list.getLength();
    ArrayList<Node> array = new ArrayList<Node>(len);

    for (int i = 0; i < len; i++) {
        Node n = list.item(i);

        if (n.getNodeType() == Node.ELEMENT_NODE) {
            array.add(n);
        }
    }
    Element[] elems = new Element[array.size()];

    return (Element[]) array.toArray(elems);
}

From source file:Estadistica.java

/**
* Metodo  para obtener el promedio//w  w w .j a va 2  s .  c  o  m
* param  lista de valores  a la que se le va a calcular el promedio
* @return el promedio
*/
public static double getAverage(ArrayList<Double> cal) {
    double sumFloat = 0;
    double averageFloat = 0;
    for (int i = 0; i < cal.size(); i++) {
        sumFloat += cal.get(i);
    }
    averageFloat = sumFloat / cal.size();
    return averageFloat;
}

From source file:StringUtils.java

/**
 * Parses a comma-seperated-list into an array;
 * /*from w w w.  ja v a  2  s. co  m*/
 * @param csl
 * @return
 */
public static String[] cslToArray(String csl) {
    if (csl == null) {
        return null;
    }
    ArrayList list = new ArrayList();
    String[] vals = csl.split(",");
    for (int i = 0; i < vals.length; i++) {
        String val = vals[i].trim();
        if (val.length() > 0) {
            list.add(val);
        }
    }
    String[] sl = new String[list.size()];
    for (int i = 0; i < sl.length; i++) {
        sl[i] = (String) list.get(i);
    }
    return sl;
    // seems GWT compiler dont like this.....
    //return (String[]) list.toArray(new String[list.size()]);
}

From source file:mlflex.helper.MathUtilities.java

/** Calculates the minimum value from a list of numeric values.
 *
 * @param values List of numeric values//from   ww w . jav a2s .c o  m
 * @return Minimum value
 * @throws Exception
 */
public static double Min(ArrayList<Double> values) throws Exception {
    if (values.size() == 0)
        throw new Exception("The list was empty, so Min could not be determined.");

    int indexOfMin = 0;

    for (int i = 1; i < values.size(); i++) {
        Double value = values.get(i);

        if (value < values.get(indexOfMin))
            indexOfMin = i;
    }

    return values.get(indexOfMin);
}

From source file:Main.java

public static <T> T[] asArrayRemoveNulls(Class<T> a_class, T[] values)
/*     */ {/*  w  w w  . j a  v  a 2  s .  c  o  m*/
    /* 509 */ArrayList valueList = new ArrayList(values.length);
    /* 510 */for (Object t : values)
    /*     */ {
        /* 512 */if (t == null)
            /*     */continue;
        /* 514 */valueList.add(t);
        /*     */}
    /*     */
    /* 517 */return (T[]) valueList.toArray((Object[]) (Object[]) Array.newInstance(a_class, valueList.size()));
    /*     */}

From source file:cn.sharesdk.net.NetworkHelper.java

public static PostResult httpPost(String url, ArrayList<NameValuePair> pairs) {
    PostResult postResult = new PostResult();
    if (pairs == null || pairs.size() == 0) {
        postResult.setSuccess(false);/*from ww  w  .jav a 2s  .com*/
        postResult.setResponseMsg("post date of the request params is null !");
        return postResult;
    }

    try {
        HttpPost httppost = new HttpPost(url);
        httppost.addHeader("charset", HTTP.UTF_8);
        httppost.setHeader("Accept", "application/json,text/x-json,application/jsonrequest,text/json");

        HttpEntity entity = new UrlEncodedFormEntity(pairs, HTTP.UTF_8);
        httppost.setEntity(entity);

        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 5000);
        httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 5000);
        HttpResponse response = httpclient.execute(httppost);
        int status = response.getStatusLine().getStatusCode();

        String resString = EntityUtils.toString(response.getEntity());
        postResult = parse(status, resString);
    } catch (Exception e) {
        Ln.i("NetworkHelper", "=== post Ln ===", e);
    }

    return postResult;
}

From source file:Main.java

public static long[] fromString(final String string, final char token) {
    if (string == null)
        return new long[0];
    final String[] items_string_array = string.split(String.valueOf(token));
    final ArrayList<Long> items_list = new ArrayList<Long>();
    for (final String id_string : items_string_array) {
        try {//from www .jav  a2s .c o  m
            items_list.add(Long.parseLong(id_string));
        } catch (final NumberFormatException e) {
            // Ignore.
        }
    }
    final int list_size = items_list.size();
    final long[] array = new long[list_size];
    for (int i = 0; i < list_size; i++) {
        array[i] = items_list.get(i);
    }
    return array;
}

From source file:Main.java

/**
 * @param newMenu//from  w w w .j  a v a 2 s  .c om
 * @param menuBar
 * @param index
 * @return The same JMenuBar, for cascading.
 *         TODO See if the same thing can be done with Container.add( component, index )
 */
public static JMenuBar addMenuAt(JMenu newMenu, JMenuBar menuBar, int index) {

    ArrayList menuList = new ArrayList();
    for (int i = 0; i < menuBar.getMenuCount(); i++) {
        if (i == index) {
            menuList.add(newMenu);
        }
        menuList.add(menuBar.getMenu(i));
    }
    menuBar.removeAll();
    //        menuBar = new JMenuBar();
    for (int i = 0; i < menuList.size(); i++) {
        JMenu menu = (JMenu) menuList.get(i);
        menuBar.add(menu);
    }
    return menuBar;
}

From source file:Main.java

public static long[] parseLongArray(final String string, final char token) {
    if (string == null)
        return new long[0];
    final String[] items_string_array = string.split(String.valueOf(token));
    final ArrayList<Long> items_list = new ArrayList<Long>();
    for (final String id_string : items_string_array) {
        try {//from  ww  w  .jav a  2  s .com
            items_list.add(Long.parseLong(id_string));
        } catch (final NumberFormatException e) {
            // Ignore.
        }
    }
    final int list_size = items_list.size();
    final long[] array = new long[list_size];
    for (int i = 0; i < list_size; i++) {
        array[i] = items_list.get(i);
    }
    return array;
}