Tuesday, 27 May 2014

public ArrayList()

public ArrayList()
Constructs an empty list with an initial capacity of ten.

import java.util.*;

class ArrayListConstructor1{
 public static void main(String args[]){
  ArrayList<Integer> myList;
  myList = new ArrayList<> ();
  
  /* Add Elements to myList */
  myList.add(10);
  myList.add(20);
  
  System.out.println("Elements in myList are");
  System.out.println(myList);
 }
}

Output
Elements in myList are
[10, 20]


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment