Junior — Senior
String equality check: value vs reference
livecode
Task condition
This example demonstrates how the == operator works when comparing strings created in different ways – as literals and through the new String constructor. The output will show whether the object references in memory are the same.
public static void main(String[] args) {
var s1 = "a";
var s2 = "a";
var s3 = new String("a");
System.out.println("s1 == s2: " + (s1 == s2));
System.out.println("s1 == s3: " + (s1 == s3));
}