Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

find the greatest number in hashmap

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
            }
        }

    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: init cap java 
Java :: string array to arraylist android 
Java :: java file get bytes 
Java :: cannot lock java compile cache as it has already been locked by this process 
Java :: how to take space separated input in java 
Java :: android ancestral navigation 
Java :: how to deselect radio button in java 
Java :: ova definition 
Java :: java how to get deltaTime 
Java :: fullscreen java jframe 
Java :: java robot left click 
Java :: from string to double andoird studio 
Java :: java how to open a link 
Java :: java read file text 
Java :: arrays.asLisy in java 
Java :: maven compiler plugin for java 13 
Java :: how to write sensor data into file android studio 
Java :: intent android open activity 
Java :: java popup message 
Java :: scan.nextline not waiting for input 
Java :: java initialize map with values in one line 
Java :: Java program to find the sum of all even numbers from 1 to 10 
Java :: java take out cn from dn 
Java :: spring data rest partial update 
Java :: get player by name spigot 
Java :: check if string has a valid number java 
Java :: android elevation not working 
Java :: java retirer derniere caractere sting 
Java :: java http request post 
Java :: status codes springboot 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =