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 void main(String[] args) {
    ArrayList<String> aList = new ArrayList<String>();
    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("5");

    ListIterator listIterator = aList.listIterator();
    while (listIterator.hasNext()) {
        System.out.println(listIterator.next());
    }//w ww . ja  va 2s . com
}

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");

    int totalElements = arrayList.size();
    for (int index = 0; index < totalElements; index++)
        System.out.println(arrayList.get(index));
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList aList = new ArrayList();
    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("java2 s .com");
    System.out.println("ArrayList: ");
    System.out.println(aList);//from   w ww.j a v  a2s.co  m
    Iterator itr = aList.iterator();
    String strElement = "";
    while (itr.hasNext()) {
        strElement = (String) itr.next();
        if (strElement.equals("2")) {
            itr.remove();
            break;
        }
    }
    System.out.println("ArrayList after removal : ");
    System.out.println(aList);
}

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<String> aList = new ArrayList<String>();
    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("java2s.com");

    ListIterator listIterator = aList.listIterator();
    while (listIterator.hasNext()) {
        System.out.println(listIterator.next());
    }/*from  ww  w .j av  a2  s . c o m*/
}

From source file:MainClass.java

public static void main(String[] a) {
    ArrayList<String> nums = new ArrayList<String>();
    nums.add("O");
    nums.add("Two");
    nums.add("Three");
    nums.add("Four");

    String s;/*  ww w .  j  ava2s  .co m*/
    Iterator e = nums.iterator();
    while (e.hasNext()) {
        s = (String) e.next();
        System.out.println(s);
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    // Build a vector of words to be sorted
    ArrayList list = new ArrayList();
    list.add("m");
    list.add("c2");
    list.add("e");
    list.add("c1");

    Collator collate = Collator.getInstance();

    CollationKey[] keys = new CollationKey[list.size()];

    for (int k = 0; k < list.size(); k++)
        keys[k] = collate.getCollationKey((String) list.get(k));

    Arrays.sort(keys);/*  ww w.  j  a v  a2  s  .c om*/

    for (int l = 0; l < keys.length; l++) {
        System.out.println(keys[l].getSourceString());
    }
}

From source file:Main.java

public static void main(String args[]) {

    ArrayList<Integer> arrlist = new ArrayList<Integer>(5);

    arrlist.add(10);
    arrlist.add(50);/*  w  ww  . j  av  a  2s .  c o  m*/
    arrlist.add(30);

    arrlist.ensureCapacity(5000);

}

From source file:Main.java

public static void main(String[] args) {
    Path myText_path = Paths.get("C:/tutorial/wiki", "wiki.txt");
    Charset charset = Charset.forName("UTF-8");
    ArrayList<String> lines = new ArrayList<>();
    lines.add("\n");
    lines.add("tutorial");

    try {/* w  ww.j  a v  a  2  s.  co  m*/
        Files.write(myText_path, lines, charset, StandardOpenOption.APPEND);
    } catch (IOException e) {
        System.err.println(e);
    }

}

From source file:Main.java

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

    arrlist.add(1);
    arrlist.add(2);// w w  w.  jav a  2 s.  co m
    arrlist.add(3);
    arrlist.add(4);
    arrlist.add(5);

    System.out.println(arrlist);

}