Java EnumMap.size()

Syntax

EnumMap.size() has the following syntax.

public int size()

Example

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


/*  w w  w .  jav  a 2 s  .co m*/

import java.util.*;

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

      System.out.println("Number of mappings:" + map.size());

      map.put(Tutorial.Javascript, "5");

      // print the new number of mappings of this map
      System.out.println("Number of mappings:" + map.size());
   }
}

The code above generates the following result.