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 list = new ArrayList();
    list.add(50);

    System.out.println(list.toString());
}

From source file:MainClass.java

public static void main(String[] a) {

    ArrayList list = new ArrayList();
    list.add("A");
    list.ensureCapacity(10);//from   ww  w .ja  v  a 2 s  .  c  om

    System.out.println(list.size());
}

From source file:MainClass.java

public static void main(String[] a) {

    ArrayList list = new ArrayList();

    list.add("A");
    list.ensureCapacity(10);/*from   w ww.j  av a 2s.c  om*/
    list.trimToSize();
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<Integer> a = new ArrayList<>();
    a.add(1);
    a.add(5);// w  w w.  java  2  s.c  om
    a.add(1);

    a.set(1, null);
    System.out.println(a.get(1));
    System.out.println(a);
}

From source file:Main.java

public static void main(String... args) {
    ArrayList<Boolean> list = new ArrayList<Boolean>();
    list.add(true);
    boolean flag = list.get(0);
}

From source file:MainClass.java

public static void main(String args[]) {
    ArrayList simpsons = new ArrayList();
    simpsons.add("Bart");
    simpsons.add("Hugo");
    simpsons.add("Lisa");
    simpsons.add("Marge");
    simpsons.add("Homer");
    simpsons.add("Maggie");
    simpsons.add("Roy");
    Comparator comp = Collections.reverseOrder();
    Collections.sort(simpsons, comp);
    System.out.println(simpsons);
}

From source file:OldStyle.java

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

    list.add("one");
    list.add("two");
    list.add("three");
    list.add("four");

    Iterator itr = list.iterator();
    while (itr.hasNext()) {
        String str = (String) itr.next(); // explicit cast needed here.

        System.out.println(str + " is " + str.length() + " chars long.");
    }//from  w w w  .  j a v  a 2 s  .  c  om
}

From source file:MainClass.java

public static void main(String[] args) {
    ArrayList list = new ArrayList();
    list.add("\u00e4pple");
    list.add("banan");
    list.add("p\u00e4ron");
    list.add("orange");

    // Obtain a Swedish collator
    Collator collate = Collator.getInstance(new Locale("sv", ""));
    Collections.sort(list, collate);

    for (int i = 0; i < list.size(); i++) {
        System.out.println(list.get(i));
    }// w ww .j a va2 s.  c  o m
}

From source file:Test.java

public static void main(String[] args) {
    ArrayList<Integer> a1 = new ArrayList<>();
    a1.add(new Integer(1));
    a1.add(2);/*from ww w .ja va 2s  .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<Integer> arrlist = new ArrayList<Integer>(5);

    arrlist.add(15);
    arrlist.add(20);/*ww w. j a v  a 2s.  c  o  m*/
    arrlist.add(25);

    System.out.println(arrlist);
}