Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Loop Thru ArrayList of ArrayList  RSS feed

 
Steve Dyke
Ranch Hand
Posts: 1782
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get the following to work but get an Error: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The conditions under which get() will throw that exception is outlined in the javadoc. (Hint: and even pointed out in the message.)
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message has the hints. Element 0 refers to the first element of the list. If the list size is 0 then there are 0 elements and therefore there is no first element to get and your attempt to get it is flagged with an "out of bounds" exception.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You tell people the end of movies too, don't you?
 
Steve Dyke
Ranch Hand
Posts: 1782
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You tell people the end of movies too, don't you?


Not usually. Was just trying to verify I has the correct syntax for the shorthand loop. I found the problem in my ArrayList of ArrayList. Had an empty element.

Thanks for all the help once again. I am sure I will be back for some more wisdom from the wise.
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that was for me. Sorry, Bear, didn't mean to preempt your hint to go to the JavaDocs.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's all good.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!