Hello, I am kind of new to java programming. Although I have programming experience but not on open systems like java,C etc.. I am trying to learn java and got confused with 2D arrays. Can anyone suggest some informative site for a detailed explaination on this topic. Somwhow this concept of 2D array is not fitting in my head. Help!! Help!!
Sun has a free downloadable extensive Java tutorial, which includes discussions of arrays. Here's a quickie overview:
Think of a two dimensional array as a set of boxes. For example, if you have an array that is 3x2, you would have three big boxes each holding two little boxes, and each little box stores data of whatever type the array was declared to hold. If you have a 3x5x8 array, you have three big boxes, each holding five medium boxes, each holding eight small boxes and each little box... you get the idea.
Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Joined: Aug 30, 2004
Thanks for the reply. That is how I also visualize conceptually. So for eg: If the array is defined as Arr, then if arr is interrogated then it should show data containing in arr and arr and arr...., but it does not ? Can u tell me more in detail how does the data reside ?
Joined: Jul 30, 2003
then if arr is interrogated then it should show data containing in arr and arr and arr...., but it does not
Actually, there is no data in arr, only another array. You can only check data when you fully dereference the array, and then only if you properly initialized the elements of the array. Just declaring an array does not initialize it with data. (See Java's initialization default values for the data type of the array.)
Also, in Java, the second-level arrays do not have to be the same size, so arr could hold a three-element array, while arr could hold a twelve element array.
Joined: Aug 30, 2004
Ok, I understand that arrays need to be initialized explicitly So assuming the array is initialized with proper values and as per ur answer Arr contains only arrays again then why does Arr show junk values? What is it that it is showing?
You can only check data when you fully dereference the array
What do you mean by the above statement ? I did not get a bit of it... and I think my answer is hidden in the quote above. [ November 17, 2004: Message edited by: Jugal Hans ]