• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jq+ code

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
//regarding this code, why does it print "null"?
public class StringArrayTest
{
public static void main(String args[])
{
String[][][] arr =
{
{ { "a", "b" , "c"}, { "d", "e", null } },
{ {"x"}, null },
{{"y"}},
{ { "z","p"}, {} }
};
System.out.println(arr[0][1][2]);
}
}

/*
the explanation of jq+ after I did the test says:
arr[0][1][2] => [0] = { { "a", "b" , "c"}, { "d", "e", null } }, [1] = { "d", "e", null } and [3] = null.
So it will print 'null'.

But I dont get why.
*/
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will try to explain.
Take the entire mad list
{
{ { "a", "b" , "c"}, { "d", "e", null } },
{ {"x"}, null },
{{"y"}},
{ { "z","p"}, {} }
}
and try to imagine it to be an unidimensional array. For this we can break it up with commas. Thus we have an array of 4 elements. Now take the first element of the said array { { "a", "b" , "c"}, { "d", "e", null } } - which again looks like an array and can be broken up by commas. Thus we have a nested array of two elements inside the first element - i.e the elements a[0][0] and a[0][1]. Since we are only concerned with a[0][1] we take a closer look at it i.e { "d", "e", null } . This again is an array of three elements a[0][1][0](="d"), a[0][1][1](="e") and a[0][1][2](=null) - our required answer.
Hope I have been clear enough.
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was very good and clear explanantion.
Thanx Saha
Rajani
[This message has been edited by Rajani Katta (edited August 16, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic