Guest User

Untitled

a guest
Jan 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. @Override
  2. public boolean equals(Object object)
  3. {
  4. boolean isEqual= false;
  5.  
  6. if (object != null && object instanceof A)
  7. {
  8. isEqual = (this.elementA == ((A) object).elementA);
  9. }
  10.  
  11. return isEqual;
  12. }
  13.  
  14. @Override
  15. public int hashCode() {
  16. return this.elementA;
  17. }
  18.  
  19. boolean contains = CollectionUtils.exists(myArrayList, new Predicate<A>() {
  20. public boolean evaluate(A theA) {
  21. // Do the comparison
  22. }
  23. });
  24.  
  25. ArrayList<String> l1 = new ArrayList<>();
  26. ArrayList<String> l2 = new ArrayList<>();
  27. l1.add("asdf");
  28. l2.add("asdf");
  29. ArrayList<ArrayList<String>> coll = new ArrayList<>();
  30. coll.add(l1);
  31. System.out.println(coll.contains(l2));
  32.  
  33. Map<Integer, A> map = new HashMap<>();
  34. A a1 = new A(1, 1);
  35. A a2 = new A(1, 2);
  36.  
  37. map.put(a1.elementA, a1);
  38.  
  39. // test if key is contained
  40. boolean contains = map.containsKey(a2.elementA);
  41.  
  42. // overwrite a1 with a2
  43. map.put(a2.elementA, a2);
  44.  
  45. Ex:
  46. List<String> myList = new ArrayList<String>();
  47.  
  48. For comparing the object value in arrayList.
  49.  
  50. Follow this Link.
Add Comment
Please, Sign In to add comment