Hashtable values() in Java

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

Syntax:

Collection<V> java.util.Hashtable.values()

This method returns a Collection view of the values contained in this map.

Parameters: NA

Returns: a collection view of the values contained in this map.

Exceptions: NA

Approach

Java

import java.util.Hashtable;

public class Hashtablevalues {
    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.values());

    }
}

Output:

[2, 1]


No comments:

Post a Comment