Home » Java programming language

Java EnumSet allOf() Method with Example

EnumSet Class allOf() method: Here, we are going to learn about the allOf() method of EnumSet Class with its syntax and example.
Submitted by Preeti Jain, on February 13, 2020

EnumSet Class allOf() method

  • allOf() method is available in java.util package.
  • allOf() method is used to return Enumset that has all of the elements of the given element type (ele_ty).
  • allOf() method is a static method, so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
  • allOf() method may throw an exception at the time of returning EnumSet object.
    NullPointerException: This exception may throw when the given parameter is null exists.


    public static EnumSet allOf(Class ele_ty);


  • Class ele_ty – represent the element type (ele_ty) class for this Enumset.

Return value:

The return type of this method is EnumSet, it retrieves Enumset that have set of elements for this Enum.


// Java program is to demonstrate the example of
// allOf(Class ele_ty) method of EnumSet

import java.util.*;

public class AllOfEnumSet {
    // Initialize a enum variable
    // with some constants

    public enum Colors {

    public static void main(String[] args) {
        // Here , we are creating an empty EnumSet
        EnumSet < Colors > es = null;

        // Display EnumSet
        System.out.println("EnumSet: " + es);

        // By using allOf() method is to 
        // get all of the elements of an enum 
        // and put into an es
        es = EnumSet.allOf(Colors.class);

        // Display Modified EnumSet
        System.out.println("Updated set: " + es);


EnumSet: null

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.