Forums Register Login

Using HashMap

+Pie Number of slices to send: Send
I have a small program here where I am using a HashMap object with a Map Reference and a Vector object with a List reference. The later works fine when passing it as a methods type to the main method.however the HashMap objects keys are output as Strings fine but the values which come from the constructors of another class do not .The program complies ok ,It is just the output which is confusing me , here`s the code:
+Pie Number of slices to send: Send
I must just add the package and import statments are present in class a1 I must have missed them in the paste
+Pie Number of slices to send: Send
The version of System.out.println() that takes an Object as a parameter automatically calls the toString() method. The default implementation of toString() produces the output that you see here. For more details, see the javadocs for Object.toString(). If you wrote this class yourself, you should override the toString() method to print useful information about the object.

HTH

Layne
+Pie Number of slices to send: Send
hi layne,
Thanks for the prompt reply as usual, just to cement my understanding of what is happening here , when you say System.out.println(foo); implements the Object classes toString method does this mean that when I create my own toString method in a2 that System...out(foo)automatically will implement that one.I have updated a2 with a toString() method and it does work :see below

Just another point on this , if my assumption is correct on the actions ive described , why does s2.getMap(); in the main method output the correct data if it does not have access to the toString method?

Thanks Danny

[ August 16, 2005: Message edited by: Daniel .j.Hyslop ]
[ August 16, 2005: Message edited by: Daniel .j.Hyslop ]
Fire me boy! Cool, soothing, shameless self promotion:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1014 times.
Similar Threads
access private member
Exam Question: I can't explain this downcasting
access a private member
exam lab gc question
passing arrays
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:13:27.