How != and == operators work on Integers in Java? [duplicate]
This question already has an answer here: Why is 128==128 false but 127==127 is true when comparing Integer wrappers in Java? 6 answers The following code seemed really confusing to me since it provided two different outputs.The code was tested on jdk 1.7. public class NotEq { public static void main(String[] args) { ver1(); System.out.println(); ver2(); } public static void ver1() { Integer a = 128; Integer b = 128; if (a == b) { System.out.println("Equal Object"); } if (a != b) { System.out.println("Different objects"); } if (a.equals(b)) { System.out.println("Meaningfully equal."); } }