Dictionary size() in Java

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

Syntax:

int java.util.Dictionary.size()

This method returns the number of entries (distinct keys) in this dictionary.

Note: Size is equivalent to the number of distinct keys in the dictionary.

Parameters: NA

Returns: the number of keys in this dictionary.

Exceptions: NA

Approach

Java

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

public class Dictionarysize {
    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);
        dictionary.put("C++", 6);

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

    }
}

Output:

3


No comments:

Post a Comment