Why does this code return false instead of true:
package com.company;
public class Main {
public static void main(String[] args) {
String fullName = "Name Lastname";
String name = "Name ";
String lastName = "Lastname";
String firstNamePlusLastName = name + lastName;
System.out.println(fullName == firstNamePlusLastName);
}
}
If I remember it right:
String firstNamePlusLastName = name + lastName;
Should create a line that points to an existing address in memory (string pool), because we have already declared a string with the value: "Name Lastname", should it not be interned automatically in the string pool and should not output be "true", since Do we already have a string with the same value in the string pool as String firstNamePlusLastname?
EDIT:
, .equals() , , Java , , , , , , "" . , .
user7451361