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) {
    System.out.println(new ArrayList().getClass().getSuperclass().getName());

}

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);/* w w  w  . java2 s .c o  m*/

    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 .  ja  v a 2s . c o  m*/
    list.trimToSize();
}

From source file:Main.java

public static void main(String... args) {
    ArrayList<Boolean> list = new ArrayList<Boolean>();
    list.add(true);/*from   w  ww .  ja  va 2s.  c  o  m*/
    boolean flag = list.get(0);
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<Integer> a = new ArrayList<>();
    a.add(1);/* w w w  .j  a  v a2s.co  m*/
    a.add(5);
    a.add(1);

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

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:Main.java

public static void main(String[] a) {
    ArrayList<String> nums = new ArrayList<String>();
    nums.clear();//from w ww.j av a2  s .c o m
    nums.add("One");
    nums.add("Two");
    nums.add("Three");

    System.out.println(nums);
    nums.set(0, "Uno");
    nums.set(1, "Dos");
    nums.set(2, "Tres");
    System.out.println(nums);
}

From source file:Main.java

public static void main(String[] a) {
    ArrayList<String> nums = new ArrayList<String>();
    nums.clear();/*www  . j av a2  s  .c o  m*/
    nums.add("One");
    nums.add("Two");
    nums.add("Three");

    System.out.println(nums);
    nums.set(0, "Uno");
    nums.set(1, "Dos");
    nums.set(2, "java2s.com");
    System.out.println(nums);
}

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