Map: containsKey(Object key) : Map « java.util « Java by API






Map: containsKey(Object key)

 


import java.util.HashMap;
import java.util.Map;

class Counter {
  int i = 1;

  public String toString() {
    return Integer.toString(i);
  }
}

public class Main {
  public static void main(String[] args) {
    Map hm = new HashMap();
    for (int i = 0; i < 10; i++) {
      Integer r = new Integer(20);
      if (hm.containsKey(r))
        ((Counter) hm.get(r)).i++;
      else
        hm.put(r, new Counter());
    }
    System.out.println(hm);
  }
}

   
  








Related examples in the same category

1.implements Map
2.java.util.Map.Entry
3.Map: clear()
4.Map: containsValue(Object value)
5.Map: equals(Object o)
6.Map: get(Object key)
7.Map.Entry: getKey()
8.Map.Entry: getValue()
9.Map: keySet()
10.Map: put(T key, T value)
11.Map: putAll(Map m)
12.Map: remove(Object key)
13.Map: size()
14.Map: values()