This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays

 
Aru Ven
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I may sound stupid..... But can anyone help me how to find out the elements in an multi dimensional array....like

. Say if this array has been initialized they how do locate an element at say [0][1][2]...& so on & also the array length.
Thx
Aruna
 
Yamuna Pattathil
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aruna,
I havent done any modifications to your array. Just go through this and find out. I have just intented your array so that it becomes self-explanatory.
 
quan zhu
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have run it and do not understand why do we get those "NullPointerException"?. I thought by default we will get some "null" in the array.
 
Yamuna Pattathil
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Equating an array to null and equating an element of an array to null makes the difference as in the following code.

 
Aru Ven
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yamuna, Thank You.
Aruna
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this strategy to "visualilze" the multi-dimensional array -
With every open brace '{' start a new dimension and with every '}' seal the most recently opened dimension.
Also, while dealing with such questions, remember that Java supports sparse arrays ie., each sub-array of a multidimensional array can be of different length. To make it simple, if you imagine a two-dimensional array as a rectangle, each row in the rectangle can have different number of elements.
Just my two cents worth...
Ajith
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aru,
You don't sound stupid. You are just braver that all the souls out there who don't understand either - but are too chicken to ask!

[This message has been edited by Cindy Glass (edited December 19, 2000).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic