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<String> trans(String[] sa) {
    ArrayList<String> als = new ArrayList<>(0);
    for (int i = 0; i < sa.length; i++) {
        als.add(sa[i]);
    }/*w  w w . j a v a  2 s.c  o m*/
    return als;
}

From source file:Main.java

private static void loadLayer(int width, int height, String[] values, ArrayList<ArrayList<Integer>> layer) {
    for (int i = 0; i < height; i++) {
        ArrayList<Integer> row = new ArrayList<>();
        for (int j = 0; j < width; j++) {
            row.add(Integer.parseInt(values[width * i + j]));
        }/* w  ww  . j ava2s  . c  o  m*/
        layer.add(row);
    }
}

From source file:Main.java

/**
 * Create an {@link ArrayList} with zero or more "objects".
 * @param objects/*from  www. j a v a2 s .  c  o m*/
 * @return ArrayList<O>
 */
@SafeVarargs
public static <O> ArrayList<O> arrayList(O... objects) {
    ArrayList<O> list = new ArrayList<>();

    for (O object : objects) {
        list.add(object);
    }

    return list;
}

From source file:Main.java

public static <T> ArrayList<T> toArrayList(Stream<T> stream) {
    ArrayList<T> result = new ArrayList<T>();
    stream.forEach(t -> result.add(t));
    return result;
}

From source file:Main.java

public static <T> ArrayList<T> add(ArrayList<T> cur, T val) {
    if (cur == null) {
        cur = new ArrayList<>();
    }/*from  ww  w.  j  av a  2  s .  com*/
    cur.add(val);
    return cur;
}

From source file:Main.java

public static List<String> toTextContent(List<Node> nodes) {
    ArrayList<String> list = new ArrayList<String>(nodes.size());
    for (Node node : nodes) {
        list.add(node.getTextContent());
    }//w w  w . j av a2  s  . c  o  m
    return list;
}

From source file:com.orig.gls.seed.Country.java

public static ArrayList getEnabledCountries() {
    ArrayList arr = new ArrayList();
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;//ww  w  .  j a v a2 s . c  o m
    List<CountryCodes> country;
    try {
        tx = session.beginTransaction();
        Criteria cr = session.createCriteria(CountryCodes.class);
        cr.add(Restrictions.eq("enabledFlg", "Y"));
        country = cr.list();
        for (CountryCodes count : country) {
            ArrayList one = new ArrayList();
            one.add(count.getCountryCode());
            one.add(count.getCountryName());
            one.add(sdf.format(count.getRcreTime()));
            arr.add(one);
        }
        tx.commit();
    } catch (Exception asd) {
        log.debug(asd.getMessage());
        if (tx != null) {
            tx.rollback();
        }
    }
    return arr;
}

From source file:Main.java

/**
 * Marshal the elements from the given enumeration into an array of the given type.
 * Enumeration elements must be assignable to the type of the given array. The array
 * returned will be a different instance than the array given.
 *//*from  ww  w.  j  ava 2  s .c  om*/
public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) {
    ArrayList<A> elements = new ArrayList<A>();
    while (enumeration.hasMoreElements()) {
        elements.add(enumeration.nextElement());
    }
    return elements.toArray(array);
}

From source file:Main.java

public static <T> List<T> copyToArrayList(List<T> fromList) {

    ArrayList<T> result = new ArrayList<T>();

    for (T listItem : fromList) {
        result.add(listItem);
    }/*ww  w  .  ja v  a  2s  .  c  o  m*/

    return result;
}

From source file:Main.java

public static ArrayList<String> cutString(ArrayList<String> list, int begin, int end) {

    ArrayList<String> newList = new ArrayList<>();

    for (int i = begin; i < end; i++) {
        newList.add(list.get(i));
    }//from   www  .  j  a  v  a  2  s  .co  m

    return newList;
}