0
uniqueVlaues
public static HashMap<Integer, String> uniqueValues(HashMap<Integer, String> a_map){ HashMap<Integer, String> hmap = new HashMap<Integer, String>(); for (Map.Entry<Integer, String> pair : a_map.entrySet()) { if(pair.getValue().equals(a_map.entrySet())){ a_map.remove(Value); } } return hmap; } hi everyone, I wanted to remove all Value(Strings) that the function receives from a_map. and will return HashMap<String, Integer> hmap = new HashMap<String, Integer>() Can someone give me some hint please. thanks
2 Answers
0
You mean you want your method to return a new map with removed duplicate values? In that case your check should be something like this:
if (!hmap.containsValue(pair.getValue())) {
hmap.put(pair.getKey(), pair.getValue());
}
0
no i actually I mean I would like to have hmap that hold only unique value of a_map.
exp if a_map holds [{2,âqâ} , {3, âeâ}, {21, âqâ}]
so now hmap should only hold [{3,âeâ}] but in terms of <String, Integer> so it shoulf be like this hmap = {âeâ, 3};
thank you, I know it is complicated