EnumSet range() Method in Java
The java.util.EnumSet.range(E start_point, E end_point) method in Java is used to create an enum set with the elements defined by the specified range in the parameters.
Enum_set = EnumSet.range(E start_point, E end_point)
Parameters: The method accepts two parameters of the object type of enum:
- start_point: This refers to the starting element that is needed to be added to the enum set.
- end_point: This refers to the last element which is needed to be added to the enum set.
Return Value: The method returns the enum set created by the elements mentioned within the specified range.
Exceptions: The method throws two types of exception:
- NullPointerException is thrown if any of the starting or the last element is NULL.
- IllegalArgumentException is thrown when the first element is greater than the last element with respect to the position.
Below programs illustrate the use of range() method:
The enum set is: [The, World, of, Geeks]
The enum set is: [RANGE_ROVER, MUSTANG, CAMARO]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.