There is an array consisting several numbers. Among them find out the pair number(that consist 2 times in that array) in java. suppose {2,5,7,8,2,3,5,6,5} in this array 2 consist 2 times so its is pair number.
i tried this way :
HashMap<Integer, Integer> hmap = new HashMap<>();
for (int i = 0; i < arr.length; i++)
{
Integer c = hmap.get(arr[i]);
if (hmap.get(arr[i]) == null)
hmap.put(arr[i], 1);
else
hmap.put(arr[i], ++c);
}