Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- public class Counter<T> {
- private final HashMap<T, Integer> map = new HashMap<T, Integer>();
- public int get(T key) {
- final Integer n = map.get(key);
- return n == null ? 0 : n;
- }
- public void count(T key) {
- map.put(key, get(key) + 1);
- }
- public HashMap<T, Integer> getMap() {
- return map;
- }
- }
Add Comment
Please, Sign In to add comment