Sobes.tech
Junior — Senior

Comparison of links in pool strings and explicitly created objects

livecode

Task condition

Code review of a method illustrating the differences in behavior of the == operator when comparing strings obtained from the String Pool and strings created via the new String() constructor.

private static void stringPool() {
    String s1 = "a";
    String s2 = "a";
    String s3 = new String("a");

    System.out.println(s1 == s2);
    System.out.println(s1 == s3);
}