In below program i am getting output as false .But as per my understanding when we add two temporary reference variable then result go inside constant pool which does not allow duplicates so we must have gotten output as true here but we are getting false as an output.Can somebody explain me reason behind this?
package com.lara;
public class Man9
{
public static void main(String[] args)
{
String s1 = "ja";
String s2 = "va";
String s3 = "ja".concat("va");
String s4 = "java";
System.out.println(s3==s4);
}
}
You need to use s3.equals(s4), not s3==s4.
Then you will get your true result.
See transcript below