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

14th Oct 2020, 12:59 AM
theChamp
theChamp - avatar
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()); }
14th Oct 2020, 3:21 AM
Aleksandrs
Aleksandrs - avatar
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
14th Oct 2020, 3:28 AM
theChamp
theChamp - avatar