Why both are not equal the output is match unmatch how? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

Why both are not equal the output is match unmatch how?

public class demomain { public static void main(String[] args) { Integer n1 = 50; Integer n2 = 50; Integer n3 = 200; Integer n4 = 200; if (n1 == n2) System.out.println("match"); else System.out.println("unmatch"); if (n3 == n4) System.out.println("match"); else System.out.println("unmatch"); } }

30th Aug 2022, 6:47 PM
Rohit Ahuja
Rohit Ahuja - avatar
1 Antwort
+ 2
https://www.sololearn.com/Discuss/2123471/?ref=app Integer instances, having value in range -128 up to 127 are cached and stored in same reference when their values are equal. 200 is out of the range for cached (pooled) instances.
30th Aug 2022, 9:45 PM
Ipang