Java Collection Tutorial - Java EnumMap.clear()








Syntax

EnumMap.clear() has the following syntax.

public void clear()

Example

In the following code shows how to use EnumMap.clear() method.

//from   w  w  w . j a v a 2 s  .  c om
import java.util.EnumMap;

// create an enum
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); 
      
      map.clear();
      
      System.out.println(map);
      
   }
}

The code above generates the following result.