jQuery in Action, 3rd edition
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: 29
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
author & internet detective

Joined: May 26, 2003
Posts: 33107

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Bruno Sant Ana

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

Thanks for the explanation, I understood it. If appears one more doubt related to this subject I'll post here.
I agree. Here's the link: http://aspose.com/file-tools
subject: array of arrays
It's not a secret anymore!