File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

ArryList of Objects

manikandan jayakumar
Ranch Hand

Joined: Aug 20, 2011
Posts: 44


i want to display arraylist of object can anyone help me? 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: 3152

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: 15092

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 8 API documentation
I agree. Here's the link:
subject: ArryList of Objects
It's not a secret anymore!