File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Empty ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Empty ArrayList" Watch "Empty ArrayList" New topic

Empty ArrayList

Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1283

No Kaustubh No Fun, Know Kaustubh Know Fun..
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

but it is not even printing the string attached with it

new ArrayList(100) doesn't mean that the list has 100 items.
API wrote:public ArrayList(int initialCapacity)
Constructs an empty list with the specified initial capacity.

It doesn't enter the loop. Why would it print the message ?

[My Blog]
All roads lead to JavaRanch
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

This is an ArrayList, not an Array.
While you have defined the initial capacity, it is still empty until you put something in it.
The initial capacity is used for determining the supported size behind the scenes so that you can reduce the time spent resizing the data structure behind the scenes if you already know (or have a good idea of) the number of items going into the ArrayList
Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1283

Got it ...Thanks Guys
wood burning stoves
subject: Empty ArrayList
It's not a secret anymore!