Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

object to string

 
kevin schmidt
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
Kevin
 
Danny Davies
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.

Danny
[This message has been edited by Danny Davies (edited September 10, 2001).]
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should work just fine. You may need to provide more detail if it still does not work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic