This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

ArryList of Objects  RSS feed

 
Ranch Hand
Posts: 44
Firefox Browser Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i want to display arraylist of object can anyone help me?




testClass.java is in /test/




'm not able to display the list. 'm getting test.testObject@....
like this?

How to get the correct values?


Thanks in advance
 
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

manikandan jayakumar wrote:
...

'm not able to display the list. 'm getting test.testObject@....
like this?
...


Please UseRealWords - Words like 'm are not understood by all

manikandan jayakumar wrote: getting test.testObject@....
like this?


Coming back to the query-
You have to override the toString method in your testObject class.
 
Java Cowboy
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you pass an arbitrary object to System.out.println, as you are doing in lines 9 and 11, Java will call the toString method on that object and print the string that that method returns.

If you do not implement your own toString method in the class of the object, then the default toString method of class Object will be used, and it will print a string that looks like: classname@hexcharacters

So, if you want your code to print something else, you have to override the toString method of your testObject class.
 
Hot dog! An advertiser loves us THIS much:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!