The JVM is caching Integer values. Hence the comparison with ==
only works for numbers between -128 and 127.
More Related Contents:
- How != and == operators work on Integers in Java? [duplicate]
- Using == operator in Java to compare wrapper objects
- Why equal operator works for Integer value until 128 number? [duplicate]
- Converting characters to integers in Java
- Inconsistent behavior on java’s ==
- Using int vs Integer
- How do I add an "L" to the end of an integer?
- In java, is there anyway to go from a array of objects that got returned to the number of objects in the array? [closed]
- How do I generate random integers within a specific range in Java?
- Why don’t Java Generics support primitive types?
- Large Numbers in Java
- Why do people still use primitive types in Java?
- What’s the difference between primitive and reference types?
- Why doesn’t Java support unsigned ints?
- Different between parseInt() and valueOf() in java?
- When to use wrapper class and primitive type
- How can I pass an Integer class correctly by reference?
- Parsing a Hexadecimal String to an Integer throws a NumberFormatException?
- How does double to int cast work in Java
- Integer vs int: with regard to memory
- Multiplication of two ints overflowing to result in a negative number
- Check if int is between two numbers
- How can I detect integer overflow on 32 bits int?
- Differences between new Integer(123), Integer.valueOf(123) and just 123
- How can I convert integer into float in Java?
- Which one to use, int or Integer
- Java storing two ints in a long
- Differences between ServletResponse and HttpServletResponseWrapper?
- What does int.class mean
- Comparing float and double primitives in Java