The moose likes Beginning Java and the fly likes object to string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "object to string" Watch "object to string" New topic

object to string

kevin schmidt
Ranch Hand

Joined: Aug 24, 2001
Posts: 85
I was wondering how a person convert an object to a string. I've tried casting, but it doesn't work. I'm calling a function from a java file that I wrote. It returns a string, but I can't say "String kevin = newName;", it doesn't work. What can I do? TIA.
Danny Davies

Joined: Sep 10, 2001
Posts: 1
every class you create is derived from the class Object, the class Object has a method toString(). So therefore once you create an instance of that class you can call the toString() method. Here's an example, hope this helps.

[This message has been edited by Danny Davies (edited September 10, 2001).]
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
It should work just fine. You may need to provide more detail if it still does not work.
I agree. Here's the link:
subject: object to string
It's not a secret anymore!