Javatpoint Logo

about string literal

By: manish*** On: Sat Jan 21 10:26:07 IST 2017     Question Reputation0 Answer Reputation0 Quiz Belt Series Points0  0Blank User
String s3="manish"+"kumar";
System.out.println(s3);
String s4=(new StringBuilder()).append("manish").append("kumar").toString();

System.out.println(s4);

System.out.println(s3==s4);//false


in string chapter you said that jvm converted like this. if jvm converted like this than how it is false. give me explanation.
Up0Down

 
You are comparing the hash code of an object i.e s3 and s4. To compare the contents of your string just use s3.equals(s4) method.Image Created0Down

By: [email protected] On: Sat Jan 21 11:02:58 IST 2017 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :0Yes0No