LinkedHashMap equals(Object) in Java

equals(Object): This method is available in java.util.LinkedHashMap 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.LinkedHashMap;

public class LinkedHashMapequals {

    public static void main(String args[]) {

        LinkedHashMap<String, Integer> linkedHashMap =
new LinkedHashMap<String, Integer>();

        linkedHashMap.put("Java", 1);
        linkedHashMap.put("Hello", 2);

        LinkedHashMap<String, Integer> o =
new LinkedHashMap<String, Integer>();

        o.put("Java", 1);
        o.put("Hello", 2);

        System.out.println(linkedHashMap.equals(o));
    }

}

Output:

true


No comments:

Post a Comment