Created
September 4, 2012 13:01
-
-
Save khotyn/3620959 to your computer and use it in GitHub Desktop.
Integer Caching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* {@link Integer} will cache the integers between -128 and 127 (inclusive). See | |
* {@link Integer#valueOf(int)} for detail implementation. | |
* | |
* @author khotyn | |
* | |
*/ | |
public class IntegerTest { | |
public static void main(String[] args) { | |
int i = 1000, j = 1000; | |
System.out.println(i == j); // The result is true. | |
Integer int1 = 100, int2 = 100; | |
System.out.println(int1 == int2); // The result is true. | |
Integer int3 = 200, int4 = 200; | |
System.out.println(int3 == int4); // The result is false. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment