File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes arrayList again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "arrayList again" Watch "arrayList again" New topic
Author

arrayList again

brian yuen
Greenhorn

Joined: Oct 20, 2003
Posts: 20
can anyone tell me what's wrong with the arrayList
the output is like :TestAccount@a18aa2
the class is called TestAccount...
i add it to an arrayList successfully like...

and use the following code to output

Thanks
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8902
    
    8

Nothing is wrong with ArrayList. Unless you override toString(), it prints out the name of the object you called it on plus a number (memory location, hash code, I forget). Override TestAccount.toString() to do something meaningful.
[ October 22, 2003: Message edited by: Joe Ess ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
brian yuen
Greenhorn

Joined: Oct 20, 2003
Posts: 20
Thank you very much, i got it now.
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
For what it's worth, because of the polymorphic nature of Java it's not necessary to cast the ArrayList elements before printing them out. The following would work just as well:

At run time the system would determine that the element being printed--addTestAcc.get(i)--is a "TestAccount", and call the appropriate "toString()" method.
You only need to do an explicit cast to call a method that's defined in that class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: arrayList again