0
Not able to understand the output. requesting to explain
public class MyClass { public static void main(String args[]) { Integer x = 127; Integer y = 127; System.out.println (x==y); x=128; y=128; System.out.println(x==y); } } Output True False Please explain why 2nd output is false
4 Respostas
+ 5
It is because the Integer class maintains an internal cache which doesn't require the instantiation of an object to store values which are frequently used from range -128 to 127 which is 1 byte.
For all the values greater than that it creates separate objects. And hence the == will return false.
https://code.sololearn.com/cn2vMn0Uyr74/?ref=app
+ 1
type of int is primitive while Integer is of class type
+ 1
Thank you so much for response. Really helped
0
Use int x & int y
Happy coding ;))