1. Literal strings within the same class in the same package represent references to the same String object.
2. Literal strings within different classes in the same package represent references to the same String object.
3. Literal strings within different classes in different packages likewise represent references to the same String object.
I found these facts in the enthuware answers ! But I just can't understand what it means , can somebody explain please !
Take a look at this stackoverflow post about string literals
Some of the posted answers explain the difference between these two statements:
To clear up your confusion a little bit from your post, if you create two string variables
that have the same literal, they will be referenced by the same object even if they are in different classes and/or packages.
Now lets say we want to create another variable that contains the string literal from the first statement above.
The variable s and x are now referencing the same memory location while the variable t does not since we created a new object for the string literal.
When you check the equality of the three you should get the following results.