Skip to content

Instantly share code, notes, and snippets.

@TrevorS
Last active January 3, 2016 11:59
Show Gist options
  • Save TrevorS/8459500 to your computer and use it in GitHub Desktop.
Save TrevorS/8459500 to your computer and use it in GitHub Desktop.
public class Test {
public static void main(String[] args) {
// Primitives
int a = 10;
int b = 10;
System.out.println("a: " + a); // 10
System.out.println("b: " + b); // 10
System.out.println("a == b: " + (a == b)); // true
// Objects
Integer c = new Integer(10);
Integer d = new Integer(10);
System.out.println("c: " + c); // 10
System.out.println("d: " + d); // 10
System.out.println("c == d: " + (c == d)); // false
System.out.println("c.equals(d): " + (c.equals(d))); // true
// More Objects
Integer e = new Integer(1000);
Integer f = new Integer(1000);
System.out.println("e: " + e); // 10
System.out.println("f: " + f); // 10
System.out.println("e == f: " + (e == f)); // false
System.out.println("e.equals(f): " + (e.equals(f))); // true
// Special Objects?
Integer g = 20;
Integer h = 20;
System.out.println("g: " + g); // 20
System.out.println("h: " + h); // 20
System.out.println("g == h: " + (g == h)); // true
System.out.println("g.equals(h): " + (g.equals(h))); // true
// More Use of the Integer Cache
Integer i = Integer.valueOf(20);
Integer j = Integer.valueOf(20);
System.out.println("i: " + i); // 20
System.out.println("j: " + j); // 20
System.out.println("i == j: " + (i == j)); // true
System.out.println("i.equals(j): " + (i.equals(j))); // true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment