java.util.Hashtable.values() Method


Description

The values() method is used to get a Collection view of the values contained in this Hashtable.

Declaration

Following is the declaration for java.util.Hashtable.values() method.

public Collection<V> values()

Parameters

NA

Return Value

The method call returns a collection view of the values contained in this map.

Exception

NA

Example

The following example shows the usage of java.util.Hashtable.values()

package com.tutorialspoint;

import java.util.*;

public class HashTableDemo {
   public static void main(String args[]) {
      
      // create hash table 
      Hashtable htable = new Hashtable(3); 

      // populate the table
      htable.put(1, "TP");
      htable.put(2, "IS");
      htable.put(3, "THE");
      htable.put(4, "BEST");
      htable.put(5, "TUTORIAL");

      System.out.println("Collection view of hash table: "+htable.values()); 
   }    
}

Let us compile and run the above program, this will produce the following result.

Collection view of hash table: [TUTORIAL, BEST, THE, IS, TP]
java_util_hashtable.htm
Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements