This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "arrayList again" Watch "arrayList again" New topic

arrayList again

brian yuen

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

Joe Ess

Joined: Oct 29, 2001
Posts: 8843

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

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.
wood burning stoves
subject: arrayList again
Similar Threads
storing stack trace into string
read text
Synchronization Issue With Threads.
Is PrintWriter Buffered?
Returning array To Method