Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Debugging multi-array

Reply
Thread Tools

Debugging multi-array

 
 
lielar
Guest
Posts: n/a
 
      03-09-2008
Hi

I have the following multi-array, I don't know how to follow it.

String [][][] arr = {
{{}, null}, {{"1", "2"}, {"1", null, "3"}},
{}, {{"1", null}}

};

I have problems knowing what is the first, second, third objects. And
it being an array of an array of an array(3x), if one value is not
specified, how can you tell?

 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      03-09-2008
lielar wrote:
> Hi
>
> I have the following multi-array, I don't know how to follow it.
>
> String [][][] arr = {
> {{}, null}, {{"1", "2"}, {"1", null, "3"}},
> {}, {{"1", null}}
>
> };
>
> I have problems knowing what is the first, second, third objects. And
> it being an array of an array of an array(3x), if one value is not
> specified, how can you tell?
>

The first index refers to the outer array, the next to the next inner
array, etc.

If you don't know in advance how long each array is, then you must check
lengths before accessing an element.

For example, to access arr[1][2][3], do this:

if (arr.length >= 2) {
String [][] arr0 = arr[1];
if (arr0.length >= 3) {
String [] arr1 = arr0[2];
if (arr1.length >= 4) {
String arr2 = arr1[3];
// use the value here
}
}
}

This is ugly. I'm sure you can find a more efficient way to do it.
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      03-09-2008
Chris wrote:
> If you don't know in advance how long each array is, then you must check
> lengths before accessing an element.


Worse, you have to check for null, too.

> For example, to access arr[1][2][3], do this:
>

if ( arr != null && arr.length >= 2) {
> String [][] arr0 = arr[1];

if ( arr0 != null && arr0.length >= 3) {
> String [] arr1 = arr0[2];

if ( arr1 != null && arr1.length >= 4) {
> String arr2 = arr1[3];
> // use the value here

// checking for null
> }
> }
> }
>
> This is ugly. I'm sure you can find a more efficient way to do it.



--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I skip debugging Ajax when debugging my code? AAaron123 ASP .Net 3 07-28-2009 04:07 PM
Debugging C vs debugging C++ jacob navia C Programming 11 10-27-2006 07:19 PM
No Debugging of C# Server-Side Script, but Code-Behind Debugging Works Johann Blake ASP .Net 1 01-05-2004 03:01 PM
Got error msg while Debugging : Error while trying to run project: ... ^CrazyCoder^ ASP .Net 3 09-15-2003 09:40 AM
Garbage Collector Debugging Rob Tillie ASP .Net 11 08-18-2003 10:39 PM



Advertisments