Guest User

Untitled

a guest
Aug 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. Java object comparison and Hashtable with Object keys
  2. MyObject x = new MyObject();
  3. MyObject y = x;
  4.  
  5. Integer x = new Integer(1);
  6. Integer y = new Integer(1);
  7. System.out.println(x == y); // False
  8. System.out.println(x.equals(y)); // True
  9.  
  10. Object o = new Object();
  11.  
  12. List<Object> l1 = new ArrayList<Object>();
  13. List<Object> l2 = new ArrayList<Object>();
  14.  
  15. l1.add(o);
  16. l2.add(o);
  17.  
  18. Object o1 = l1.get(0);
  19. Object o2 = l2.get(0);
  20.  
  21. System.out.println(o1 == o2); // prints true
  22.  
  23. String s = "hello";
  24. List<String> l = new ArrayList<String>();
  25. l.add(s);
  26. s = "world";
  27. System.out.println(l.get(0)); // prints hello
Add Comment
Please, Sign In to add comment