-
Copy string to string.
Hi to all,
I just have a very begginers question and I was wondering if you can help me.
Let's say that I am having a variable a in a class b and a variable c in the class that I am working now. Both of the variables are strings. How can I copy the contents of variable c to variable a?
I tried something like
b.a.valueOf(c.getText().trim()); but it gave me the following error:
The static method valueOf(Object) from the type String should be accessed in a static way
Thank you very much for your time.
-
I'd use public getters and setters to get c's value and set a's value.
also, look up the String API for the the valueOf(...) method. It is called String.valueOf(some primitive here) and returns the primitive's value as a String. You shouldn't call it "on a String" variable as that would be meaningless.
-
Hi!
Thank's a lot for the reply. I managed to make it work by using getters and setters however, I was wondering if there is an easier way for doing that. In general, to take a vlaue of a string, , where 'a' is a String object and assign it to different string object 'b' by doing b=valueof(a), should be enough, shouldn't be?
Thanks a lot!
-
To directly assign the value of String a to b, all you need to do is this:
The getters / setters have little to do with this but instead is to help your program be a well-behaving object oriented program.
-
Your help is much appreciated! Thank you.