Skip to content

Instantly share code, notes, and snippets.

@khotyn
Created September 4, 2012 13:01
Show Gist options
  • Save khotyn/3620959 to your computer and use it in GitHub Desktop.
Save khotyn/3620959 to your computer and use it in GitHub Desktop.
Integer Caching
/**
* {@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