This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList and IndexOutOfBoundsException

 
Sanjeev Singh
Ranch Hand
Posts: 381
  • 0
  • 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: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • 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: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic