I know that if I have 2 string variables with the same value, they point to the same string object because of the java string pool.
Here is an example:
String test = "1234";
String test2 = "1234";
System.out.println(test == test2);
System.out.println("1234" == test2);
the output is the following:
true
true
But if I have the following code, it prints that they aren't the same object
String test = "1234";
int i = 1234;
String s = "" + i;
System.out.println(test == s);
System.out.println("1234" == s);
Output:
false
false
Anyone would explain to me the reason for that behavior, please?