Sobes.tech
Junior — Senior

String equality check in Java

livecode

Task condition

Explore how the == operator works when comparing string objects. Find out which strings refer to the same object in memory and which are located in different places.

public class Test1 {
    public static void main(String[] args) {
        var x = "a";
        var y = "a";
        var z = new String("a");

        System.out.println("x == y: " + (x == y));
        System.out.println("x == z: " + (x == z));
    }
}