9
What’s the difference of assigning a value to a variable by creating an object and assigning Unboxing at 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 ==
will give false
, but with equals()
is equal to true
. These concepts I understood well.
But I doubt because it does not equal if I assign another variable
String nome2 = "nome";
System.out.println("nome == nome2 " + (nome == nome2)); //resultado true
If you assign the value to a variable without creating an object, it creates the value in the same memory variable?
– Everson Souza de Araujo