equals(Object): This method is available in java.util.HashMap class of Java.
Syntax:
boolean java.util.AbstractMap.equals(Object o)
This method takes one argument. 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: 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.HashMap;public class HashMapequals {public static void main(String[] args) {HashMap<String, Integer> hashMap =new HashMap<String, Integer>();hashMap.put("Hello", 1);hashMap.put("World", 2);HashMap<String, Integer> o =new HashMap<String, Integer>();o.put("Hello", 1);o.put("World", 2);System.out.println(hashMap.equals(o));}}
Output:
true
No comments:
Post a Comment