contains(Object): This method is available in java.util.EnumSet class of Java.
Syntax:
boolean java.util.AbstractCollection.contains(Object o)
This method takes one argument of type Object as its parameter. This method returns true if this collection contains the specified element
Parameters: One parameter is required for this method.
o: element whose presence in this collection is to be tested.
Returns: true if this collection contains the specified element.
Throws:
1. ClassCastException - if the type of the specified element is incompatible with this collection.
2. NullPointerException - if the specified element is null and this collection does not permit null elements.
Approach
Java
import java.util.EnumSet;public class EnumSetcontains {public enum Colour {RED, GREEN, YELLOW, ORANGE};public static void main(String[] args) {EnumSet<Colour> enumSet = EnumSet.allOf(Colour.class);System.out.println(enumSet.contains(Colour.GREEN));}}
Output:
true
No comments:
Post a Comment