String s1 = "Hello"; String s2 = "Hello"; String s3 = new String(s1); String s4 = s2.clone();
s1==s2 is true and s2.equals(s3) is true.
So I have some questions.Hear my thoughts first.
When we have 2 strings and we compare them with the '=' operator, we compare their addresses in the memory and not the values.When we use the equals method we compare the values.
Am I Correct?
If I am, s1 and s2 have the same addresses because we didnt use the new word that indicates new space in the memory.And s1-s2-s3 have the same value which is "Hello" but s3 has different address than s1-s2.
And my final question is when i use the clone method what is happening?
I mean s4 contains the "Hello" word?Or s4==s2?(if the address thing i said its true)


Ask A New Question
Reply






MultiQuote









|