LinkedHashMap toString() in Java

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

Syntax:

String java.util.AbstractMap.toString()

This method returns a string representation of this map.

Parameters: NA

Returns: a string representation of this map.

Exceptions: NA

Approach

Java

import java.util.LinkedHashMap;

public class LinkedHashMaptoString {

    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.toString());
    }

}

Output:

{Java=1, Hello=2}


No comments:

Post a Comment