This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes converting objects into strings... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "converting objects into strings..." Watch "converting objects into strings..." New topic

converting objects into strings...

Ron Sibayan

Joined: Jan 02, 2004
Posts: 5
Hi guys,
I was just wondering if anyone had any suggestions on the best way to go about converting an object into a string? the object is being generated by an ActionEvent linked to a JComboBox selection. ie I have a JComboBox which holds 5 possible options (1-5).
As far as I can tell (which probably isn't that far), the only way I can get the selected option is to use the getSelectedItem() method, however I need to use the outcome as an argument for another method which requires a string.

should I be using a diferent enquiry method to retreive the comboBox selection, or should I convert it once the object is out?

Ron Sibayan
Ruben Steins

Joined: Nov 22, 2002
Posts: 15

Does this work? The toString() method is inherited from Object, isn't it?

[ January 07, 2004: Message edited by: Ruben Steins ]
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Since it is very possible that you'd want to do other things to the selected object, I'd leave the "getOrderInput()" method alone (i.e., have it return to selected object itself).
If you need to pass a string to some method, call the "getOrderInput()" method and then convert it to a String. If you are going to use the "toString()" method, make sure you override it the appropriate class so it returns a relevant value.
Ron Sibayan

Joined: Jan 02, 2004
Posts: 5
Thanks guys, youve been a big help
I agree. Here's the link:
subject: converting objects into strings...
It's not a secret anymore!