Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multidimensional array

 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two nested for loops that iterate from 0 to < the array.length should work nicely.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49405
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such thing as a 2D array. You do realise you are going to hit some nulls when you iterate that array?
 
Edwin Torres
Ranch Hand
Posts: 55
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like they said, initialize the third row (to avoid the null) and use a nested loop:
 
Greg Brannon
Bartender
Posts: 563
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Working with arrays of arrays can be confusing, requiring extrapolating simple ideas you probably already know into more complex ones in ways you might not think of or realize are possible. For that reason, I put together a short runnable example that should answer most of your questions. Please ask if you have more.
 
Winston Gutkowski
Bartender
Pie
Posts: 10422
63
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edwin Torres wrote:Like they said, initialize the third row (to avoid the null) and use a nested loop:

Or indeed:
Winston
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic