wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Empty ArrayList" Watch "Empty ArrayList" New topic
Author

Empty ArrayList

Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1270



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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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
Rancher

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: 1270

Got it ...Thanks Guys
 
 
subject: Empty ArrayList
 
Similar Threads
Arraylist set(index i, Object o) method Exception
How can I manually add values to ArrayList[]
Help with Arrays and ArrayLists
Can we decrease the size of the ArrayList ?.
How to use ArrayLists in a program.