aspose file tools*
The moose likes Beginning Java and the fly likes ArryList of Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ArryList of Objects" Watch "ArryList of Objects" New topic
Author

ArryList of Objects

manikandan jayakumar
Ranch Hand

Joined: Aug 20, 2011
Posts: 44

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
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

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.

Mohamed Sanaulla | My Blog
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14149
    
  18

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArryList of Objects