SHARE
TWEET

Untitled

a guest Jun 16th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class hashmapcheck {
  2. public static void main(String args[]) {
  3.     Person abhishek = new Person("abhishek");
  4.     Map<Person,String> mapCheck = new HashMap<Person,String>();
  5.     mapCheck.put(abhishek,"ancd");
  6.     abhishek.setName("defg");
  7.     System.out.println(mapCheck.get(abhishek));  //line which i try to undertand
  8. }
  9.      
  10. public class Person {
  11. public String getName() {
  12.     return name;
  13. }
  14.  
  15. public void setName(String name) {
  16.     this.name = name;
  17. }
  18.  
  19. public Person(String name) {
  20.     this.name = name;
  21. }
  22.  
  23. String name;
  24.  
  25. @Override
  26. public boolean equals(Object o) {
  27.     if (this == o) return true;
  28.     if (o == null || getClass() != o.getClass()) return false;
  29.  
  30.     Person person = (Person) o;
  31.  
  32.     return name != null ? name.equals(person.name) : person.name == null;
  33. }
  34.  
  35. @Override
  36. public int hashCode() {
  37.     return name != null ? name.hashCode() : 0;
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top