Sobes.tech
Junior — Senior

Integer Object Pool and Reference Comparison

livecode

Task condition

Learn how autoboxing works in Java and how to compare Integer objects using the == operator when the values are inside and outside the Integer cache range (from -128 to 127).

public static void main(String[] args) {
    Integer x = 100;
    Integer y = 100;

    Integer p = 300;
    Integer q = 300;

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