public abstract class EnumSet<E extends Enum<E>>
where E specifies the elements.
Method | Description |
---|---|
allOf(Class<E> elementType) | Creates an enum set that contains all elements of the specified element type. |
clone() | Returns a copy of this set. |
complementOf(EnumSet<E> s) | Creates an enum set with the same element type as the specified set, initially containing all elements of this type that are not in the specified set. |
copyOf(Collection<E> c) | Generates an enum set from the specified collection. |
copyOf(EnumSet<E> s) | Creates an enum set with the same element type as the specified enum set, with the same elements at first (if any). |
noneOf(Class<E> elementType) | This method generates an empty enum set with the specified element type. |
of(E e) | Creates an enum set with the specified element as the first element. |
range(E from, E to) | Creates an enum set with all of the elements in the range defined by the two endpoints specified. |
import java.util.EnumSet;
// Enum
enum Week { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY,FRIDAY,SATURDAY };
// Main class
public class COderz {
// Main driver method
public static void main(String[] args) {
// Creating a set
EnumSet<Week> set1, set2, set3, set4;
// Adding elements
set1 = EnumSet.of(Week.SATURDAY, Week.MONDAY,
Week.FRIDAY, Week.SUNDAY);
set2 = EnumSet.complementOf(set1);
set3 = EnumSet.allOf(Week.class);
set4 = EnumSet.range(Week.WEDNESDAY, Week.SATURDAY);
// Printing corresponding elements in Sets
System.out.println("Set 1: " + set1);
System.out.println("Set 2: " + set2);
System.out.println("Set 3: " + set3);
System.out.println("Set 4: " + set4);
}
}
Set 1: [SUNDAY, MONDAY, FRIDAY, SATURDAY]
Set 2: [TUESDAY, WEDNESDAY, THURSDAY]
Set 3: [SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY]
Set 4: [WEDNESDAY, THURSDAY, FRIDAY, SATURDAY]
Note: also read about the AbstractSet in Java
If you like my post, please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…
View Comments