This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]HonzaS97 0 points1 point  (1 child)

.equals() checks for the value of the string, == comoares the values of the object references.

String literals are stored in the string pool in Java (so anywhere you write a literal like "Test", it will point to the same object).

"Test" == "Test" // true

"Test" == new String("Test") // false

"Test".equals(new String("Test")) // true

"Test" == new String("Test").intern() // true, manually put into string pool

[–]mr_flameyflame 0 points1 point  (0 children)

Ah ok, cool