Sobes.tech
Junior — Senior

Analysis of string object comparison by references

livecode

Task condition

This example demonstrates a method that shows how string comparison works in Java using the == operator. The method outputs the results of comparing references of different string variables to illustrate how the string pool and new object creation work.

private static void stringPool() {
    String first = "a";
    String second = "a";
    String third = new String("a");

    System.out.println(first == second);
    System.out.println(first == third);
}