size(): This method is available in java.util.EnumSet class of Java.
Syntax:
int java.util.AbstractCollection.size()
This method returns the number of elements in this collection.
Note: If this collection contains more than Integer.MAX_VALUE elements return Integer.MAX_VALUE.
Parameters: NA
Returns: the number of elements in this collection.
Exceptions: NA
Approach
Java
import java.util.EnumSet;public class EnumSetsize {public enum Colour {RED, GREEN, YELLOW, ORANGE};public static void main(String[] args) {EnumSet<Colour> enumSet = EnumSet.allOf(Colour.class);System.out.println(enumSet.size());}}
Output:
4
No comments:
Post a Comment