javascript map max value
let m = new Map([['a', 2], ['b',4], ['c',6]])
console.log([...m.entries()].reduce((a, e ) => e[1] > a[1] ? e : a))
Run code snippet
javascript map max value
let m = new Map([['a', 2], ['b',4], ['c',6]])
console.log([...m.entries()].reduce((a, e ) => e[1] > a[1] ? e : a))
Run code snippet
javascript map max value
let m = new Map([['a', 2], ['b',4], ['c',6]])
console.log("Max:", Math.max(...m.values()))
Run code snippet
find max value in map
public class NewClass4 {
public static void main(String[] args)
{
HashMap<Integer,Integer>map=new HashMap<Integer, Integer>();
map.put(1, 50);
map.put(2, 60);
map.put(3, 30);
map.put(4, 60);
map.put(5, 60);
int maxValueInMap=(Collections.max(map.values())); // This will return max value in the Hashmap
for (Entry<Integer, Integer> entry : map.entrySet()) { // Itrate through hashmap
if (entry.getValue()==maxValueInMap) {
System.out.println(entry.getKey()); // Print the key with max value
}
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us