Dictionary toString() in Java

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

Syntax:

String java.lang.Object.toString()

This method returns a string representation of the object.

Parameters: NA

Returns: a string representation of the object.

Exceptions: NA

Approach

Java

import java.util.Dictionary;
import java.util.Hashtable;

public class DictionarytoString {
    public static void main(String[] args) {

        Dictionary<String, Integer> dictionary =
new Hashtable<String, Integer>();

        dictionary.put("Hello", 10);
        dictionary.put("Java", 4);
        dictionary.put("C++", 17);

        System.out.println(dictionary.toString());

    }
}

Output:

{Java=4, C++=17, Hello=10}


No comments:

Post a Comment