File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes array of arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "array of arrays" Watch "array of arrays" New topic

array of arrays

Bruno Sant Ana

Joined: May 17, 2012
Posts: 27
Hi guys,

I did a code that have two arrays, one I call array1 and the other array2, two of them two-dimensional. What's the difference between the 2 implementations bellow? Is there any difference? Because I've never seen this kind of implementation where you inicialize the array without passing the number of colums: byte[][] array12 = new byte[3][];
I saw this only in the book about certification Java.

Being more especific...

Is this

the same of it?

Internaly that declaration byte[][] array1 = new byte[3][2]; creates an array of arrays?

Thank you very much
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30516

Yes. THose two are equivalent. The first is obviously easier to read and write.

The reason you only see the later in a certification book is that people don't generally use that approach in real life. The certification is testing a deeper understanding to see if you know what the first approach (convenience shortcut) is doing.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bruno Sant Ana

Joined: May 17, 2012
Posts: 27
Hi Jeanne,

Thanks for the explanation, I understood it. If appears one more doubt related to this subject I'll post here.
It is sorta covered in the JavaRanch Style Guide.
subject: array of arrays