Example usage for java.util ArrayList ArrayList

List of usage examples for java.util ArrayList ArrayList

Introduction

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

Prototype

public ArrayList() 

Source Link

Document

Constructs an empty list with an initial capacity of ten.

Usage

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();

    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");

    System.out.println(arrayList.get(0));
    System.out.println(arrayList.get(1));
    System.out.println(arrayList.get(2));
}

From source file:Main.java

public static void main(String args[]) {
    ArrayList<Integer> arrlist = new ArrayList<Integer>();

    arrlist.add(1);/*from  ww w  .  j  ava  2  s  . c  o  m*/
    arrlist.add(2);
    arrlist.add(3);
    arrlist.add(4);
    arrlist.add(5);

    System.out.println(arrlist);

}

From source file:Test.java

public static void main(String[] args) {
    ArrayList<Integer> a1 = new ArrayList<>();
    a1.add(new Integer(1));
    a1.add(2);/* ww w.ja  v  a2 s  .  co m*/
    ArrayList<Float> a2 = new ArrayList<>();
    a2.add(new Float(3.0));
    a2.add(new Float(4.0));
    displayElements(a1, a2, 12);

}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();

    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");

    Object obj = arrayList.remove(1);
    System.out.println(obj + " is removed from ArrayList");

    for (String str : arrayList)
        System.out.println(str);/*from w  w w  .j a  v a 2 s  .c  o  m*/
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");

    arrayList.add(1, "INSERTED");
    for (String str : arrayList)
        System.out.println(str);/*from www .j a v a2 s .  co m*/
}

From source file:Main.java

public static void main(String[] args) {
    List list = new ArrayList();

    list.add("1");
    list.add("2");
    list.add("3");

    list.add("java2s.com");

    System.out.println("List has:" + list.size());
}

From source file:Main.java

public static void main(String[] args) {
    List list = new ArrayList();
    list.add("Item 1");
    list.add("Item 2");

    if (list.contains("Item 1")) {
        System.out.println("True");
    } else {/* w  ww  . j a va  2 s . co m*/
        System.out.println("False");
    }
}

From source file:Main.java

public static void main(String[] argv) {
    List<Integer> intlist = new ArrayList<Integer>();

    intlist.add(new Integer(123));
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();

    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");
    arrayList.add("4");
    arrayList.add("5");

    Object[] objArray = arrayList.toArray();

    for (Object obj : objArray)
        System.out.println(obj);//from w w w  .  j  av  a2s  .c o  m
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<Integer> al = new ArrayList<Integer>();
    al.add(new Integer(1));
    al.add(new Integer(2));
    al.add(new Integer(3));
    al.add(new Integer(4));
    al.add(new Integer(5));

    System.out.println("contents of al : " + al);
    Object ia[] = al.toArray(); // get array
    int sum = 0;//from  w  w  w.  j  a v a 2s.  com

    for (int i = 0; i < ia.length; i++) {
        sum += ((Integer) ia[i]).intValue();
    }
    System.out.println("Sum is :" + sum);
}