• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Making the array print clear english?

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have my code here but whenever i print, a part of the print is showing up in an unreadable format. any help as to what i need to do?



prints:

Fred 21
Jo 43
Harry 78
Zoe 37
[Data@1540e19d, Data@677327b6, Data@14ae5a5, Data@7f31245a]
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When you try to print any object, that is not a string, the println() method will call the toString() method of the object, in order to get the string representation, so that it can print it.

Since your Data class, did not implement the toString() method, it will inherit it from its super class. And with the Object class, the toString() method returns the name of the class along with the Identity hash for the instance.

Henry
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:
When you try to print any object, that is not a string, the println() method will call the toString() method of the object, in order to get the string representation, so that it can print it.

Since your Data class, did not implement the toString() method, it will inherit it from its super class. And with the Object class, the toString() method returns the name of the class along with the Identity hash for the instance.

Henry




Would this be more appropriate?

 
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

orry kaplan wrote:Would this be more appropriate?

Did you compile and run this code? what does this print?
  • Method name getName and getAge woould look better rather than GetName and GetAge.
  • Posting complete code would definitely increase the chances of getting answer.
  •  
    Marshal
    Posts: 80099
    413
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    orry kaplan wrote:. . . Would this be more appropriate? . . .

    No. Deciding what to print shou‍ld be a task done inside the class, and you are here trying to do it outside the class. You shou‍ld override the toString method.
     
    What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
    We need your help - Coderanch server fundraiser
    https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic