All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bitbucket.vietduc179.common.DataStructure.CountItem Maven / Gradle / Ivy

package org.bitbucket.vietduc179.common.DataStructure;

import java.util.HashMap;

public class CountItem {
    public CountItem() {
        items = new HashMap();
    }
    
    public void addItem(String item) {
        if (items.containsKey(item)) {
            Long val = items.get(item);
            items.put(item, val + 1);
        } else {
            Long val = (long) 1;
            items.put(item, val);
        }
    }
    
    public String getTheMostItem() {
        String ch = "";
        long count_max = -1;
        for (HashMap.Entry item : items.entrySet()) {
            if (item.getValue() > count_max) {
                count_max = item.getValue();
                ch = item.getKey();
            }
        }
        return ch;
    }
    
    HashMap items;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy