EnumSet equals(Object) in Java

equals(Object): This method is available in java.util.EnumSet class of Java.

Syntax:

boolean java.util.AbstractSet.equals(Object o)

This method takes one argument of type Object as its parameter. This method compares the specified object with this set for equality.

Note: Returns true if the given object is also a set, the two sets have the same size, and every member of the given set is contained in this set.

Parameters: One parameter is required for this method.

o: object to be compared for equality with this set.

Returns: true if the specified object is equal to this set.

Exceptions: NA

Approach

Java

import java.util.EnumSet;

public class EnumSetequals {
    public enum Colour {
        RED, GREEN, YELLOW, ORANGE
    };

    public static void main(String[] args) {

        EnumSet<Colour> enumSet = EnumSet.allOf(Colour.class);

        EnumSet<Colour> enumSet1 = EnumSet.allOf(Colour.class);
        System.out.println(enumSet.equals(enumSet1));

    }
}

Output:

true


No comments:

Post a Comment