What's different about assigning a value to the variable by creating an object and assigning unboxing to a direct value?
String s4 = new String("nome");
String nome = "nome";
System.out.println("nome == s4 " + (nome == s4)); //retorna false
If I compare these two variables with ==
it will give false
, however with equals()
equals true
. These concepts I understood well.
But I have doubts because it does not matter if I assign another variable
String nome2 = "nome";
System.out.println("nome == nome2 " + (nome == nome2)); //resultado true