TransWikia.com

How to find the biggest VALUE (not a key) in a HashMap?

Stack Overflow Asked by Marika on December 16, 2021

How to find the five?

HashMap<Integer, Integer> hmap = new HashMap<Integer, Integer>();
hmap.put(98, 3);
hmap.put(-120, 2);
hmap.put(12, 5);
hmap.put(344, 1);
hmap.put(-220, 1);

I tried this but it doesn’t like my hmap.

System.out.println(Collections.max(hmap));

One Answer

You can get the value of map using hmap.values() then use Collections.max to get max value

Collections.max(hmap.values());

Answered by Eklavya on December 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP