LinkedHashMap clone() in Java

clone(): This method is available in java.util.LinkedHashMap class of Java.

Syntax:

Object java.util.HashMap.clone()

This method returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned.

Parameters: NA

Returns: a shallow copy of this map.

Exceptions: NA

Approach

Java

import java.util.LinkedHashMap;

public class LinkedHashMapclone {

    public static void main(String args[]) {

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

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

        System.out.println(linkedHashMap.clone());

    }

}

Output:

{Java=1, Hello=2}


No comments:

Post a Comment