See this interesting article:
String is Really Special
The designers of Java decided to retain primitive types in an
object-oriented language, instead of making everything an object, so
as to improve the performance of the language. Primitives are stored
in the call stack, which require less storage spaces and are cheaper
to manipulate. On the other hand, objects are stored in the program
heap, which require complex memory management and more storage spaces.
For performance reason, Java's String is designed to be in between a
primitive and a class.
Also:
Java has provided a special mechanism for keeping the String literals
- in a so-called string common pool..
When you do:
String myStr1 = "Hello";
String myStr2 = "Hello";
Then
myStr1 == myStr2 is true, because they're both stored in the pool (Read the article).
But if you construct a new String object:
String myStr1 = new String("Hello");
String myStr2 = new String("Hello");
Then the references are not equal.
I highly recommend to visit the JLS. It says that Strings are treated in a different way, just like that :)
String something = "Value";"