File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Two and Three dimensional array

 
Ravi Ahuja
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


[x]
consider the following code can anyone explain me wat exactly is this code upto:?...thanks in advance
[/x]


[quoute]
public class Qaa75 {
public static void main(String[] args) {
String[][][] arr = {
{ {}, null },{ { "1", "2" },{ "1", null, "3" } } ,{}{{ "1",null } }
};
System.out.println(arr.length + arr[1][2].length);
}
}

[/quoute]
[ans]
The above code when compiled gives an array index out of bound exception can anyone explain as in how it works....
and please give me a simple example of something else is well other then this code
Thanks[/ans]
 
Saurabh Vyas
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following are the examples of 3D array :


regards
Saurabh
 
Amresh Singh
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The code that you have posted has compilation error at the third 2-D array...
I modified the code which looks like this.

public static void main(String[] args) {
String[][][] arr =
{
{ {}, null },
{ { "1", "2" },{ "1", null, "3" } } ,
{{},{ "1",null } }
};


System.out.println(arr.length + arr[1][2].length);
}

in the expression arr[1][2].length we are trying to access 3rd one dimensional array from second 2-D array. But the length of second 2-D array is 2. That's why AyyayIndexOutOfBoundException.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic