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 ArrayList<Double> stringToDoubleList(String s, String delimeter) {
    String[] fields = s.split(delimeter);
    ArrayList<Double> ret = new ArrayList<Double>();
    for (int i = 0; i < fields.length; i++) {
        ret.add(Double.parseDouble(fields[i].trim()));
    }//ww  w .  ja va  2s  . c  o m
    return ret;
}

From source file:Main.java

public static ArrayList<File> getFilesInPath(String path) {
    File pathFile = new File(path);
    if (pathFile != null) {
        File[] files = pathFile.listFiles();
        ArrayList<File> result = new ArrayList<>();
        for (int i = 0; i < files.length; ++i) {
            result.add(files[i]);
        }/* w  ww. j  a  v  a2 s  . c om*/
        result.add(0, pathFile.getParentFile());
        return result;
    } else {
        return null;
    }
}

From source file:Main.java

public static ArrayList<Integer> asList(int... arr) {
    ArrayList<Integer> list = new ArrayList<>(arr.length);
    for (int i = 0; i < arr.length; i++) {
        list.add(Integer.valueOf(arr[i]));
    }/*from w  w w. j  a v a2  s . c o  m*/
    return list;

}

From source file:Main.java

/**
 * converts an object array into a collection of object arrays
 * /*from  ww w.ja  v  a  2 s  .  c o  m*/
 * @param items
 * @return
 */
public static Collection<Object[]> asCollection(Object[] items) {
    ArrayList<Object[]> ret = new ArrayList<Object[]>();
    for (int i = 0; i < items.length; i++) {
        ret.add(new Object[] { items[i] });
    }
    return ret;
}

From source file:Main.java

/**
 * @param array A collection of elements to be included in the returned ArrayList
 * @return An ArrayList that includes all the elements passed in via the array parameter
 *///from   w  w w  .  j  a  v a2  s.c om
public static <T> ArrayList<T> toArrayList(final T... array) {
    final ArrayList<T> retValue = new ArrayList<T>();
    for (final T item : array)
        retValue.add(item);
    return retValue;
}

From source file:Main.java

/**
 * @param items The Collection of items to be converted to an ArrayList
 * @return An ArrayList containing the elements in the set
 */// w ww. java  2s . c om
public static <T> ArrayList<T> toArrayList(final Collection<T> items) {
    final ArrayList<T> retValue = new ArrayList<T>();
    for (final T item : items)
        retValue.add(item);
    return retValue;
}