I am a newbie just like you, but I'll try to help:
> when the s object is print using iterator, why the output show like this :
> [EMAIL PROTECTED]
When you iterate through your collection and print the class object
using: System.out.println(s);
It is printing the reference of the object, not the object content.
There are 2 ways to fix this:
1. Add the accessor methods to get the class properties, i.e add
getName, getAge methods to MyOwnClass; then when you iterate through
the collection, print out s.getName() and s.getAge.
2. Override the toString method in the MyOwnClass to display the class
properties:
void String toString() {
return "Name is " + name + "Age = " + age;
}
Then when you iterate through the collection, your System.out.println
(s) would display the "s" class properties.
HTH
definitely not a master!
norman.
On Nov 16, 1:45 pm, "Agung Prasetyo" <[EMAIL PROTECTED]> wrote:
> Hi, the java master, i have the class like this :
> public class MyOwnClass
> {
> String name;
> int age;
>
> public MyOwnClass(String name,int age)
> {
> this.name = name;
> this.age = age;
> }
>
> }
>
> And i add this class instance object to the HashSet object --> s
> s.add(new MyOwnClass("Paris",19));
>
> when the s object is print using iterator, why the output show like this :
> [EMAIL PROTECTED]
>
> please help me ! i'm very confuse the following code.
> why when i add the object Integer ex : s.add(new Integer(8));
> why the output is 8
> Thanks very much.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---