equals(Object): This method is available in java.util.EnumMap class of Java.
Syntax:
boolean java.util.EnumMap.equals(Object o)
This method takes one argument of type Object as its parameter. This method compares the specified object with this map for equality. Returns true if the given object is also a map and the two maps represent the same mappings.
Parameters: One parameter is required for this method.
o: the object to be compared for equality with this map.
Returns: true if the specified object is equal to this map.
Exceptions: NA
Approach
Java
import java.util.EnumMap;public class EnumMapequals {public enum Colour {RED, GREEN, YELLOW, ORANGE};public static void main(String[] args) {EnumMap<Colour, String> enumMap =new EnumMap<Colour, String>(Colour.class);enumMap.put(Colour.RED, "Red");enumMap.put(Colour.GREEN, "Green");enumMap.put(Colour.YELLOW, "Yellow");enumMap.put(Colour.ORANGE, "Orange");EnumMap<Colour, String> enumMap2 =new EnumMap<Colour, String>(Colour.class);enumMap2.put(Colour.RED, "Red");enumMap2.put(Colour.GREEN, "Green");enumMap2.put(Colour.YELLOW, "Yellow");enumMap2.put(Colour.ORANGE, "Orange");System.out.println(enumMap.equals(enumMap2));}}
Output:
true
No comments:
Post a Comment