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


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

public V get(Object key)


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

/*w  w  w . j a v  a2  s . c  o  m*/

import java.util.*;

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");


      // get the value for Tutorial.CSS
      String value = map.get(Tutorial.CSS);

      System.out.println("Tutorial.CSS value:" + value);
      System.out.println("Tutorial.Javascript value:" + map.get(Tutorial.Javascript));

The code above generates the following result.