clear(): This method is available in java.util.EnumSet class of Java.
Syntax:
void java.util.AbstractCollection.clear()
This method removes all of the elements from this collection. The collection will be empty after this method returns.
Parameters: NA
Returns: NA
Throws:
UnsupportedOperationException - if the clear operation is not supported by this collection.
Approach
Java
import java.util.EnumSet;public class EnumSetclear {public enum Colour {RED, GREEN, YELLOW, ORANGE};public static void main(String[] args) {EnumSet<Colour> enumSet = EnumSet.allOf(Colour.class);enumSet.clear();System.out.println(enumSet);}}
Output:
[]
No comments:
Post a Comment