A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/java/util/java_util_enumset.htm below:

Java EnumSet Class

Java EnumSet Class Introduction

The Java EnumSet class is a specialized Set implementation for use with enum types. Following are the important points about EnumSet −

Class declaration

Following is the declaration for java.util.EnumSet class −

public abstract class EnumSet<E extends Enum<E>>
   extends AbstractSet<E>
   implements Cloneable, Serializable
Class methods Methods inherited

This class inherits methods from the following classes −

Creating an EnumSet Example

The following example shows the usage of Java EnumSet of(E) method to populate the EnumSet instance. We've created a enum Numbers. Then a EnumSet instance is created using a enum value and resulted enumSet is printed.

package com.tutorialspoint;

import java.util.EnumSet;

public class EnumSetDemo {

   // create an enum
   public enum Numbers {
      ONE, TWO, THREE, FOUR, FIVE
   };

   public static void main(String[] args) {

      // create a set that contains an enum
      EnumSet<Numbers> set = EnumSet.of(Numbers.ONE);

      // print set
      System.out.println("Set:" + set);
   }
}

Let us compile and run the above program, this will produce the following result −

Set:[ONE]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4