if we made three strings in java through string literal String A = "hel"+"lo"; String B = "lo"; String C = "hel"+B; . A == C be true but output is false.. as both will share same memory in stringpool. i am bit confused why this is happening.
Code that prints false:
public class Main {
public static void main(String[] args) {
String A = "hel" + "lo";
String B = "lo";
String C = "hel" + B;
System.out.println(A == C);
}
}
Code that prints true:
public class Main {
public static void main(String[] args) {
String A = "hel" + "lo";
String B = "lo";
String C = "hel" + "lo";
System.out.println(A == C);
}
}
Why do I get different results as both are the same?