string pool
The shared store that lets equal string literals be one object.
The JVM's table of interned strings; identical literals and compile-time constant expressions refer to one pooled object, which is why == sometimes appears to work for strings.
Examples
"yes" == "yes"is true for two literals, but text read from input is a new object, so compare withequals.
See also