jQuery in Action, 2nd edition*
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 41


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

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

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
jQuery in Action, 2nd edition
subject: ArryList of Objects
Similar Threads
Writing objects to files and reading them back into the UI
Sorting with Comparable
core java
Unable to populate Data in Jtable from Sparql result
Most specific method.......