I'm following the Java tutorial on Primitive Data Types. Early on, it states that
In Java SE 8 and later, you can use the int data type to represent an unsigned 32-bit integer, which has a minimum value of 0 and a maximum value of 2^32-1. Use the Integer class to use int data type as an unsigned integer.
What I'm understanding from this quote is that I can now store up to 2^32-1 as an int as long as I use the Integer wrapper object rather than the int primitive data type. But when I tried this out, my compiler is complaining that the value I'm using is too large, 2^31. I've tried this using both the primitive data type and Object.
Integer integerObjectLarge = 2147483648; //2^31
int integerPrimitiveLarge = 2147483648; //2^31
How exactly do I use an int/Integer to store unsigned value, such as 2^31?
-1
, which2147483647
doesn't give any problems – Harbird