I originally wrote my code with "name1 == name2" as the comparing if condition and it didn't work so had to replace it with ".equals". My question is about why it didn't work. From what I understand, "==" checks the place in memory where it is stored rather than a direct comparison. So it wouldn't work with two separately declared objects, but shouldn't it work with simple Strings? I thought that if two declared Strings were exactly the same, then java would store them in the temporary memory at the same location to save space and therefor "==" would work. Anyone know why it doesn't work in this case? Here is my code for reference:
public class Solution {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String name1 = reader.readLine();
        String name2 = reader.readLine();
        if(name1.equals(name2)){
            System.out.println("The names are identical");
        }else if(name1.length() == name2.length()){
            System.out.println("The names are the same length");
        }
    }
}