Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how get most comon element in map java

public static void main(String[] args) {
    ArrayList<String> string;
    string = new ArrayList<>(Arrays.asList("Mah", "Bob", "mah", "bat", "MAh", "BOb"));
    Map<String, Integer> wordMap = new HashMap<String, Integer>();

    for (String st : string) {
        String input = st.toUpperCase();
        if (wordMap.get(input) != null) {
            Integer count = wordMap.get(input) + 1;
            wordMap.put(input, count);
        } else {
            wordMap.put(input, 1);
        }
    }
    System.out.println(wordMap);
    Object maxEntry = Collections.max(wordMap.entrySet(), Map.Entry.comparingByValue()).getKey();
    System.out.println("maxEntry = " + maxEntry);
}
Comment

PREVIOUS NEXT
Code Example
Java :: poo pledin 3.0 
Java :: re-loop after last item in array java 
Java :: jsp multipart/form-data submition 
Java :: Java Enable assertion in package names 
Java :: how to enforce xml dtd validation in java 
Java :: fly dfguyghj: Javascript 
Java :: diamonds 
Java :: Add space to the left and right sides of a cell 
Java :: write arraylist to outputstream java byte file 
Java :: what is xml file in java 
Java :: how to create 2d arrazlist in java 
Java :: how to add a hyperlink in a string in java mail 
Java :: split() String android 
Java :: java blocks 
Java :: java webelement how to double click 
Java :: List Double, fixed size 
Java :: lmethod java 
Java :: java tcp readline not working 
Java :: https://javahungry.blogspot.com/2020/01/list-of-lists-in-java.html 
Java :: v2ray 
Java :: Display a Text Five Times 
Java :: super class and concrete class in java 
Java :: Caused by: java.lang.IllegalStateException: stream has already been operated upon or closed 
Java :: adding matrix 
Java :: control statements 
Java :: Java byte Keyword 
Java :: combine .proto in android studio project 
Java :: .class to .java 
Java :: Copying Arrays Using Assignment Operator Java 
Java :: ways to add properties to Bean Spring 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =