Tuesday 27 May 2014

public ArrayList(int initialCapacity)

public ArrayList(int initialCapacity)
Constructs an empty list with the specified initial capacity.

import java.util.*;

class ArrayListConstructor2{
 public static void main(String args[]){
  ArrayList<Integer> myList;
  myList = new ArrayList<> (5);
  
  /* 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]


1. Throws IllegalArgumentException if the specified initial capacity is negative

Prevoius                                                 Next                                                 Home

No comments:

Post a Comment