wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "ArrayList" Watch "ArrayList" New topic


Venkat Ramsimha
Ranch Hand

Joined: Dec 28, 2004
Posts: 127
consider the following code:
import java.util.*;
class ArrayDemonstration
public static void main(String args[])
ArrayList list = new ArrayList(2);//line 1
Iterator i = list.iterator();
while(i.hasNext())//line 2
System.out.print(i.next());//line 3



On the above program i have some queries:
1.In the line marked with line1 the 'ArrayList ' has to accept only 2 elements but its accepting more than 2 elements .I would like to know whether its advisable to place the total no of elements in the 'ArrayList'
2.I would like to know the functionality of the lines marked with line2,line3

tx in advance,
Animesh Shrivastava
Ranch Hand

Joined: Jul 19, 2004
Posts: 298
Hello carl,
Go through the java api

it will give u a better explanation about that,
basically the constructor for the array list which u have used here,
specifies the capacity of the arraylist and not the size, thats not fixed and it increases whenever the number of elements goes beyond the capacity.
I agree. Here's the link: http://aspose.com/file-tools
subject: ArrayList
Similar Threads
New type of for loop?
Mixing and non Generics
Using instance variables
Generics Confusion
Printing a List backwards