// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.HashMap;
import java.util.Map;

public class Count {
    private static int count(String srch, String s) {
        int res = 0;
        for(String part : s.split("[ ,]")) {
            if(part.equals(srch)) {
                res++;
            }
        }
        return res;
    }
    private static Map<String,Integer> allCount(String s) {
        Map<String,Integer> res = new HashMap<String,Integer>();
        for(String part : s.split("[ ,]")) {
            if(res.containsKey(part)) {
                res.put(part, res.get(part) + 1);
            } else {
                res.put(part, 1);
            }
        }
        return res;
    }
    public static void main(String[] args) {
        String s = "1 22 333 4444,333,22,1";
        System.out.println(count("22", s));
        System.out.println(count("4444", s));
        System.out.println(count("44", s));
        System.out.println(allCount(s));
    }
}
