Get the keys with the biggest values from a hashmap?

后端 未结 8 1731
时光取名叫无心
时光取名叫无心 2020-12-06 02:01

I have a HashMap defined like this...

HashMap uniqueNames = new HashMap();

It stor

8条回答
  •  甜味超标
    2020-12-06 02:17

    If you only want the value you can go for this. In this example I had to get the maximum frequency of a number among an array of 'n' numbers

          {
            int n = sc.nextInt();
            int arr[] = new int[n];
            int freq = 1;
            int i;
            Map myMap = new HashMap();
    
            for(i=0;imax)    
                max = myMap.get(arr[i]);
    
           }
            System.out.println(max);
         }
    

提交回复
热议问题