Hashtable size() in Java

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

Syntax:

int java.util.Hashtable.size()

This method returns the number of keys in this hashtable.

Parameters: NA

Returns: the number of keys in this hashtable.

Exceptions: NA

Approach

Java

import java.util.Hashtable;

public class Hashtablesize {
    public static void main(String[] args) {
        Hashtable<String, Integer> hashtable =
new Hashtable<String, Integer>();

        hashtable.put("Hello", 1);
        hashtable.put("World", 2);

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

    }
}

Output:

2


No comments:

Post a Comment