I'm trying to find the key corresponding to the maximum value in a HashMap. My declaration is as follows:
HashMap<Node, Double> coinD= new HashMap<>();
However, when I try to use an anonymous function to compare two values inside the entrySet of this map, I get a type casting error:
Node bestNode = Collections.max(coinD.entrySet(), (e1, e2) -> e1.getValue() - e2.getValue()).getKey();
Returns a type mismatch on e1.getValue() and e2.getValue(): cannot convert from double to int. Where is this coming from? Why is an integer necessary here; why can't the function use doubles to compare? Does the function I defined require ints, or does .getValue() have to return an int? Any help would be greatly appreciated!