Integer Cache in Java

Before starting with the post, try to find the output for below code snippet: Integer a = 100; Integer b = 100; System.out.println(a == b); Integer c = 1000; Integer d = 1000; System.out.println(c == d); Note the answer somewhere, we will come back to it after looking at some concepts which will help in answering this. Auto-boxing and Auto-unboxing in Java Integer i = 2 doesn’t make sense as i is an object reference and you are assigning it a literal....

June 28, 2020 · 3 min · Vivek Bhadauria