0

in Java is it exactly the same for a String been transferred to char array and then changed back? i.e.

String a = "Hello World";
String b = String.copyValueOf(a.toCharArray());

are String a and b guaranteed to be the same?

Yes I know in this situation they would be equal, but I mean, are they guaranteed to be equal in any case no matter what was the value?

2
  • ideone.com/yy3FCU Commented Jun 12, 2014 at 19:28
  • 1
    You can run the code and get your answer, no need to post a question here. Commented Jun 12, 2014 at 19:29

1 Answer 1

3

They are going to be equal, not the same.

That is: both variables will contain the address of different String objects. But a comparison of the objects referenced by both variables using the String.equals() method will return true.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.