Example usage for java.util ArrayList add

List of usage examples for java.util ArrayList add

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:Main.java

public static <E> ArrayList<E> newArrayList(Iterable<E> iterable) {
    if (iterable == null) {
        throw new NullPointerException();
    }//from  w w  w.  j  a  va2 s  .c o m
    ArrayList<E> list = new ArrayList<E>();
    for (Iterator<E> i = iterable.iterator(); i.hasNext();) {
        list.add(i.next());
    }
    return list;
}

From source file:Main.java

public static <T> void addArrayListToArrayList(ArrayList<T> array, ArrayList<T> arrayList) {
    Iterator<T> it = array.iterator();
    while (it.hasNext()) {
        arrayList.add(it.next());
    }/*from  ww w .ja  va  2  s  .c om*/
}

From source file:Main.java

public static List<Integer> parseIntegerJsonList(JSONArray array) throws JSONException {
    if (array == null) {
        return new ArrayList<Integer>();
    }//  w w  w  .  j  a  v  a  2 s  .  co m

    int size = array.length();
    ArrayList<Integer> list = new ArrayList<Integer>(size);
    for (int i = 0; i < size; i++) {
        list.add(array.getInt(i));
    }

    return list;
}

From source file:Main.java

public static String[] getJSONObjectKeys(JSONObject inputObject) {
    Iterator keys = inputObject.keys();
    ArrayList<String> objectKeys = new ArrayList<String>();

    while (keys != null && keys.hasNext()) {
        objectKeys.add((String) keys.next());
    }// ww w . j a v  a 2s .  c  om
    String[] returnArray = new String[objectKeys.size()];
    return objectKeys.toArray(returnArray);
}

From source file:Main.java

public static HashMap<Integer, ArrayList<Double>> transposeHashMap(HashMap<Integer, ArrayList<Double>> data) {
    HashMap<Integer, ArrayList<Double>> dataT = new HashMap<Integer, ArrayList<Double>>();
    //transpose data to get data for each sensor channel
    for (int i = 0; i < data.get(0).size(); i++) {
        ArrayList<Double> tmp = new ArrayList<Double>();
        for (int j = 0; j < data.size(); j++) {
            tmp.add(data.get(j).get(i));
        }/*from  w  w w.  j  a  v a  2s . c  o  m*/
        dataT.put(i, tmp);
    }
    return dataT;
}

From source file:Main.java

public static List<Boolean> parseBooleanJsonList(JSONArray array) throws JSONException {
    if (array == null) {
        return new ArrayList<Boolean>();
    }//from   w  w w .  jav a 2  s. c  om

    int size = array.length();
    ArrayList<Boolean> list = new ArrayList<Boolean>(size);
    for (int i = 0; i < size; i++) {
        list.add(array.getBoolean(i));
    }

    return list;
}

From source file:Main.java

/**
 * Converts the elements passed into a list.
 * Almost the same as Java's Collections.asList, but returns an ArrayList.
 */// w w  w  .j  av a 2 s .co m
// @SafeVarargs
public static <T> ArrayList<T> asList(T... strings) {
    ArrayList<T> list = new ArrayList<T>(strings.length + 1);
    for (T s : strings) {
        list.add(s);
    }
    return list;
}

From source file:Main.java

/**
 * Creates a new {@link ArrayList} with the inferred type
 * using the given elements./*from   w  w  w  . j a v a 2 s. com*/
 */
public static <T> ArrayList<T> alist(Collection<T> vals) {
    ArrayList<T> ret = new ArrayList<T>(vals.size());
    for (T v : vals)
        ret.add(v);
    return ret;
}

From source file:Main.java

/**
 * Creates a new {@link ArrayList} with the inferred type
 * using the given elements./*from   w  w w  . j a v a 2 s . c o m*/
 */
@SafeVarargs
public static <T> ArrayList<T> alist(T... vals) {
    ArrayList<T> ret = new ArrayList<T>(vals.length);
    for (T v : vals)
        ret.add(v);
    return ret;
}

From source file:Main.java

public static <E> ArrayList<E> iterableAsArrayList(Iterable<? extends E> elements) {
    if (elements == null) {
        throw new NullPointerException("elements");
    }/*from ww  w.  j  av  a2s .co  m*/
    if (elements instanceof Collection) {
        return new ArrayList<>((Collection) elements);
    } else {
        ArrayList<E> list = new ArrayList<>();
        for (E element : elements) {
            list.add(element);
        }
        return list;
    }
}