How to Check Whether Specified Value in a HashTable in Java


In this example, we will learn how to check whether the specified value in a HashTable in Java.

Source Code

package com.beginner.examples;

import java.util.Hashtable;

public class ValueInHashTable {

  public static void main(String[] args) {
    // Create a HashTable object
    Hashtable tables = new Hashtable();
    tables.put("1", "A");
    tables.put("2", "B");

    boolean b = tables.containsValue("A"); // check whether the specified value in a HashTable
    System.out.println(b);
  }
}

Output:

true

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments