publicclassTwoSum {Map<Integer,Integer> map =newHashMap<>();// Add the number to an internal data structure.publicvoidadd(int number) {map.merge(number,1, (a, b) -> a + b); }// Find if there exists any pair of numbers which sum is equal to the value.publicbooleanfind(int value) {for (Integer key :map.keySet()) {int target = value - key;if (target != key &&map.containsKey(target)) returntrue;if (target == key &&map.get(target) >=2) returntrue; }returnfalse; }}// Your TwoSum object will be instantiated and called as such:// TwoSum twoSum = new TwoSum();// twoSum.add(number);// twoSum.find(value);