Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ArrayList and IndexOutOfBoundsException  RSS feed

 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanjeev,

I works when you say 4, "E" instead of 5. Any reason behind this behavior to throw an exception??
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!