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 to get sting value into object 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 "to get sting value into object" Watch "to get sting value into object" New topic

to get sting value into object

jazy smith
Ranch Hand

Joined: Nov 18, 2009
Posts: 101
Hi all,

I have one String 'DETAILS' and I want to pass this string as Order class' object. i.e.

how can I pass 'DETAILS' to the getOrder method ?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I'm confused. Do you want the String to become an Order? Or a property of Order?
Or this:

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

It's hard to answer this question, because we don't know what your Order and WestOrder classes look like, and what the DETAILS string contains. A String is a totally different kind of object than an Order or a WestOrder. It sounds like this:

Trying to fit a square peg in a round hole

There is no generic way to pass a String to a method that takes a different kind of object. Does the DETAILS string contain information on an order? What does it look like? Maybe you need to parse the string, make an Order object and set the fields of that object using information found in the string?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Then you'll need a constructor/method that accepts a String and returns a WestOrder

But I would really recommend you to read some tutorials about object orientation and java.
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1659

uhm.... why not just add an additional parameter? Ahh I guess it doesn't matter.

What you need to do is first associate the string with the WestOrder. Something like this (and forgive me cause I don't have a lot of your code to work with):

Then when you send the WestOrder to the setOrder, you can get the details out like this:

Does that help?

When you do things right, people won't be sure you've done anything at all.
I agree. Here's the link:
subject: to get sting value into object
Similar Threads
object reference
sorting of a collection of Java classes
iBatis object relationships
Getting java.rmi.UnmarshalException: unrecognized method hash: method not supported by remote object
POST/PUT using CXF REST web service