Home » Java programming language

Java EnumSet noneOf() Method with Example

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

EnumSet Class noneOf() method

  • noneOf() method is available in java.util package.
  • noneOf() method is used to creates an empty enum set with the given element type (ele_ty).
  • noneOf() method is a static method, it is accessible with classname and if we try to access the method with class object then we will not get an error.
  • noneOf() method may throw an exception at the time of creating blank enum set.
    NullPointerException: This exception may throw when the given parameter is null exists.


    public static EnumSet noneOf(Class ele_ty);


  • Class ele_ty – represents the Class object of the element type for this EnumSet.

Return value:

The return type of this method is EnumSet, it returns nothing.


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

import java.util.*;

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

    public enum Colors {

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

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

        // Display Modified EnumSet
        System.out.println("EnumSet.allOf(Colors.class): " + all_of);

        // By using noneOf() method is to 
        // get none of the elements exists
        // in an EnumSet none_of
        EnumSet none_of = EnumSet.noneOf(Colors.class);

        // Display Modified EnumSet
        System.out.println("EnumSet.noneOf(Colors.class): " + none_of);


EnumSet.allOf(Colors.class): [RED, BLUE, GREEN, PURPLE, YELLOW]
EnumSet.noneOf(Colors.class): []


Comments and Discussions



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

© some rights reserved.