Preparing for SCJP6.0
Henry Wong wrote:
A "two dimensional array" is just an array of arrays. And an array is just an object.... so, you do it the same way you would for any other object.
Preparing for SCJP6.0
Praveen Srinivasan wrote:
I tried the same way as any other Object but i can't add the values to the HashMap...can you provide with a example...
Henry Wong wrote:
Can you show us what you tried?
Preparing for SCJP6.0
Henry Wong wrote:
I assume that you want to put the array into the hashmap, and not the element of the array, right? To do that....
Henry
Preparing for SCJP6.0
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Preparing for SCJP6.0
Praveen Srinivasan wrote:
Henry Wong wrote:
Can you show us what you tried?
I tried a simple code as below i don't know if this is right way
SCJP6.0,My blog Ranchers from Delhi
Praveen Srinivasan wrote:I'm using JDK1.3 could that be a problem?.... Also there was no complie time error only runtime error...
But without the print statement(line no: 9) no errors are shown...
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Shanky Sohar wrote:
even this will work but it will put only the value of arr[0][0] at the specified,,not a complete array
Preparing for SCJP6.0
Praveen Srinivasan wrote:I did the coding as below
I'm using JDK1.3 could that be a problem?.... Also there was no complie time error only runtime error...
But without the print statement(line no: 9) no errors are shown...
SCJP6.0,My blog Ranchers from Delhi
Praveen Srinivasan wrote:
Shanky Sohar wrote:
even this will work but it will put only the value of arr[0][0] at the specified,,not a complete array
Yeah... but is there possibilities to put the complete array
SCJP6.0,My blog Ranchers from Delhi
Andrew Monkhouse wrote:
Praveen Srinivasan wrote:I'm using JDK1.3 could that be a problem?.... Also there was no complie time error only runtime error...
But without the print statement(line no: 9) no errors are shown...
What was the runtime error?
Preparing for SCJP6.0
Shanky Sohar wrote:
I think Henry already explains that see above
Preparing for SCJP6.0
Praveen Srinivasan wrote:
Shanky Sohar wrote:
I think Henry already explains that see above
That doesn't work its shows a runtime error as in my previous post
SCJP6.0,My blog Ranchers from Delhi
Shanky Sohar wrote:
see my earlier post for why you are getting a error
Preparing for SCJP6.0
SCJP6.0,My blog Ranchers from Delhi
Shanky Sohar wrote:show us the code.
Preparing for SCJP6.0
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Praveen Srinivasan wrote:
Shanky Sohar wrote:show us the code.
SCJP6.0,My blog Ranchers from Delhi
SCJP6.0,My blog Ranchers from Delhi
Preparing for SCJP6.0
Shanky Sohar wrote:This should work fine.....
Preparing for SCJP6.0
Praveen Srinivasan wrote:Thanks for the explanation Andrew... so the System.out.println doesn't resolve the statement by itself...
SCJP6.0,My blog Ranchers from Delhi
SCJP6.0,My blog Ranchers from Delhi
Preparing for SCJP6.0
Praveen Srinivasan wrote:
Sorry shanky that didn't solve the problem.... it showed the runtime error as Andrew gave...
SCJP6.0,My blog Ranchers from Delhi
Shanky Sohar wrote:
It is because of the difference between JDK1.3 and JDK1.6..
Andrew Monkhouse wrote:
Later versions of Java didn't do much better: while they no longer give you a runtime exception, they still don't know how to handle an array of arrays.
Preparing for SCJP6.0
Andrew Monkhouse wrote:
This is still not good enough to print out the contents - the System.out.println method still does not know what to do with an array of arrays. One solution is to use the Arrays.toString method to display the contents of an array. However it only works on an individual array. So my loop from lines 14 to 16 goes through every outer array, printing the contents of the inner array.
OCPJP 6
Vinoth Kumar Kannan wrote:
Andrew Monkhouse wrote:
This is still not good enough to print out the contents - the System.out.println method still does not know what to do with an array of arrays. One solution is to use the Arrays.toString method to display the contents of an array. However it only works on an individual array. So my loop from lines 14 to 16 goes through every outer array, printing the contents of the inner array.
java.util.Arrays.deepToString(arr) can be used in that case. It iterates in through the array elements & calls toString() in them. If the elements are in turn arrays again, it goes in deeper..and so on.. This comes in handy when you want to print multi-dimensional arrays.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Andrew Monkhouse wrote:
Vinoth Kumar Kannan wrote:
Andrew Monkhouse wrote:
This is still not good enough to print out the contents - the System.out.println method still does not know what to do with an array of arrays. One solution is to use the Arrays.toString method to display the contents of an array. However it only works on an individual array. So my loop from lines 14 to 16 goes through every outer array, printing the contents of the inner array.
java.util.Arrays.deepToString(arr) can be used in that case. It iterates in through the array elements & calls toString() in them. If the elements are in turn arrays again, it goes in deeper..and so on.. This comes in handy when you want to print multi-dimensional arrays.
Unfortunately java.util.Arrays.deepToString(arr) has only been around since JDK 1.5, and Praveen is using JDK 1.3. Otherwise an excellent suggestion.
SCJP6.0,My blog Ranchers from Delhi
Praveen Srinivasan wrote:I'm using JDK1.3 could that be a problem?
Preparing for SCJP6.0
luck, db
There are no new questions, but there may be new answers.
Darryl Burke wrote:
1.3? I'd guess that was EOLed before you wrote your first line of Java code.
And your sigline says
Preparing for SCJP6.0
Preparing for SCJP6.0
Always! Wait. Never. Shut up. Look at this tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|