new ArrayList < E > () : ArrayList « java.util « Java by API






new ArrayList < E > ()

  
/**
 *Output: 
Initial size of al: 0
Size of al after additions: 7
Contents of al: [C, A2, A, E, B, D, F]
Size of al after deletions: 5
Contents of al: [C, A2, E, B, D] 
 */

import java.util.ArrayList;

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

    System.out.println("Initial size of al: " + al.size());

    al.add("C");
    al.add("A");
    al.add("E");
    al.add("B");
    al.add("D");
    al.add("F");
    al.add(1, "A2");

    System.out.println("Size of al after additions: " + al.size());

    System.out.println("Contents of al: " + al);

    al.remove("F");
    al.remove(2);

    System.out.println("Size of al after deletions: " + al.size());
    System.out.println("Contents of al: " + al);
  }
}           
         
    
  








Related examples in the same category

1.new ArrayList(Collection c)
2.ArrayList: add(E o)
3.ArrayList: add(int index, E element)
4.ArrayList: addAll(Collection c)
5.ArrayList: addAll(int index, Collection c)
6.ArrayList: clear()
7.ArrayList: contains(Object elem)
8.ArrayList: equals(Object o)
9.ArrayList: ensureCapacity(int minCapacity)
10.ArrayList: get(int index)
11.ArrayList: indexOf(Object elem)
12.ArrayList: isEmpty()
13.ArrayList: iterator()
14.ArrayList: lastIndexOf(Object o)
15.ArrayList: listIterator()
16.ArrayList: remove(int index)
17.ArrayList: remove(Object o)
18.ArrayList: removeAll(Collection c)
19.ArrayList: retainAll(Collection c)
20.ArrayList: set(int index, T element)
21.ArrayList: size()
22.AbstractList: subList(int fromIndex, int toIndex)
23.ArrayList: toArray()
24.ArrayList: toArray(T[] a)
25.ArrayList: trimToSize()
26.for each loop for ArrayList