fork download
  1. import java.util.*;
  2. public class Main
  3. {
  4. public static void main(String[] args) {
  5. int [] arr={1,1,2,4,4,4};
  6. HashMap<Integer,Integer> map=new HashMap<>();
  7. for(int i=0;i<arr.length;i++){
  8. map.put(arr[i],map.getOrDefault(arr[i],0)+1);
  9.  
  10. }
  11. int max=-1;
  12. int mxvalue=Integer.MIN_VALUE;
  13. int min=-1;
  14. int mnvalue=Integer.MAX_VALUE;
  15. for(int key:map.keySet()){
  16. if(map.get(key)>mxvalue){
  17. max=key;
  18. mxvalue=map.get(key);
  19. }
  20. if(map.get(key)<mnvalue){
  21. min=key;
  22. mnvalue=map.get(key);
  23. }
  24. }
  25. System.out.println("max "+max+" "+"min "+min);
  26. }
  27. }
Success #stdin #stdout 0.11s 55420KB
stdin
Standard input is empty
stdout
max 4 min 2