Max keys and value from HashMap
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Collections;
public class MaxValueMap {
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( "Max Value keys::"+entry.getKey()+ "Max value::" +entry.getValue());
}
}
}
}
Max value of the Map
Max Value keys::2Max value::60
Max Value keys::4Max value::60
Max Value keys::5Max value::60
Max keys and value from HashMap
Reviewed by Mukesh Jha
on
11:59 PM
Rating:
No comments:
Add your comment