Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Java object comparison and Hashtable with Object keys
- MyObject x = new MyObject();
- MyObject y = x;
- Integer x = new Integer(1);
- Integer y = new Integer(1);
- System.out.println(x == y); // False
- System.out.println(x.equals(y)); // True
- Object o = new Object();
- List<Object> l1 = new ArrayList<Object>();
- List<Object> l2 = new ArrayList<Object>();
- l1.add(o);
- l2.add(o);
- Object o1 = l1.get(0);
- Object o2 = l2.get(0);
- System.out.println(o1 == o2); // prints true
- String s = "hello";
- List<String> l = new ArrayList<String>();
- l.add(s);
- s = "world";
- System.out.println(l.get(0)); // prints hello
Add Comment
Please, Sign In to add comment