aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ArrayList and IndexOutOfBoundsException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "ArrayList and IndexOutOfBoundsException" Watch "ArrayList and IndexOutOfBoundsException" New topic
Author

ArrayList and IndexOutOfBoundsException

Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
I was trying to execute the the Program

I got IndexOutOfBoundsException .
Does this means that the dynamic growing of the ArrayList doesnot happen when we add an element using indexes?

When I reexecuted with the initial capacity =10 ,got the same exception.

So what initialCapacity is doing in the constructor of ArrayList?
[ December 17, 2006: Message edited by: Sanjeev Kumar Singh ]

~Sanjeev Singh<br />SCJP 1.5
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Sanjeev,

I works when you say 4, "E" instead of 5. Any reason behind this behavior to throw an exception??


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

I think the code below will help you.

This is the add method as defined,



Hope, now you can see why your code throws the exception. Hope this helped.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArrayList and IndexOutOfBoundsException
 
Similar Threads
List Interface
Generic
Form a tree parent -childs from String
automatic display of the java list on mouseover an image
comparable program counstructor not found exception