Hi Rafał,
On Apr 5, 11:18 pm, Rafał Laczek <rafal_lac...@wp.pl> wrote: > Hi, > > I have a problem to display MyOwnClass objects. > Set myhs=new HashSet(); > String msg = new String(); > myhs.add(new String ("Rafał")); > myhs.add(new String ("Edyta")); > myhs.add(new MyOwnClass("Ewelinka", 9)); > myhs.add(new MyOwnClass("Ola", 16)); > myhs.add(new Integer (5)); > myhs.add(new Integer (6)); > myhs.add(new Integer (7)); > > for (Iterator iter = myhs.iterator(); iter.hasNext(); ){ > System.out.println(msg+" HashSet: "+iter.next()+"\n"); You've created an empty String for msg and as I see, there is no assignment. You are trying to print with System.out.println. msg + " HashSet: " is a String to which you add the object returned by iter.next(). So the system tries to convert this object to a String and calls the toString() method. If you do not redefine, the toString() ob object will be printed. HTH Ewald --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to javaprogrammingwithpassion@googlegroups.com To unsubscribe from this group, send email to javaprogrammingwithpassion-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---