aspose file tools*
The moose likes Beginning Java and the fly likes Array : Multi-dimensional Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array : Multi-dimensional" Watch "Array : Multi-dimensional" New topic
Author

Array : Multi-dimensional

Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
This compiles and runs



This compiles but throws NullPointer exception



Can someone please explain this ?


Regards,<br />Arnab
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18103
    
  39

In the first case, you created an array of int arrays -- and created the int array for each element.

In the second case, you just created an array of int arrays -- but did not create the int array for each element.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
How can you say that "did not create the int array for each element" ? Did not understand.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18103
    
  39

Originally posted by Arnb Sen:
How can you say that "did not create the int array for each element" ? Did not understand.


That is how it works... when you say...



Java will create you an array of int arrays but will not create each element. To do that, you must...



And also notice that each array element does not have to be an int array of the same size.

Henry
 
wood burning stoves
 
subject: Array : Multi-dimensional
 
Similar Threads
Result of the Code
Constructing multidimensional arrays
how to access the elements of multidimension array using for each loop?
Im having problems with writing this program :(
How to create multidimension array using for each loop?