Java Collection Tutorial - Java EnumMap.containsKey(Object key)








Syntax

EnumMap.containsKey(Object key) has the following syntax.

public boolean containsKey(Object key)

Example

In the following code shows how to use EnumMap.containsKey(Object key) method.

/*from   w ww  . jav  a2s . c o m*/
import java.util.EnumMap;

enum Tutorial {

   CSS, Python, PHP, Java, Javascript
};
public class Main {
   public static void main(String[] args) {
      EnumMap<Tutorial, String>  map =
              new EnumMap<Tutorial, String> (Tutorial.class);

      map.put(Tutorial.CSS, "1");
      map.put(Tutorial.Python, "2");
      map.put(Tutorial.PHP, "3");
      map.put(Tutorial.Java, "4");

      System.out.println(map);

      boolean contains = map.containsKey(Tutorial.CSS);

      System.out.println("Tutorial.CSS has a mapping:" + contains);

      contains = map.containsKey(Tutorial.Javascript);

      System.out.println("Tutorial.Javascript has a mapping:" + contains);

   }
}

The code above generates the following result.