CodesJava

Easy learning with example program codes

how to search a value in hashtable?


Hashtable:

Hashtable extends Dictionary class and implements Map interface. It contains elements in key-value pair. It not allowed duplicate key. It is synchronized. It can’t contain null key or value. It uses hashcode() method for finding the position of the elements.

We can use containsValue() method to search a value in hashtable.

Example:

package com.codesjava;
 
import java.util.Hashtable;
 
public class Test {
  public static void main(String args[]){
	//Create Hashtable object.
	Hashtable<String, String> hashtable = new Hashtable<String, String>();
	//Add objects to the Hashtable.
	hashtable.put("1", "Jai");
	hashtable.put("2", "Mahesh");
	hashtable.put("3","Vivek");
        System.out.println(hashtable);
        if(hashtable.containsValue("Vivek")){
            System.out.println("The Hashtable contains value Vivek");
        } else {
            System.out.println("The Hashtable does not contains value Vivek");
        }
  }
}

Output

{3=Vivek, 2=Mahesh, 1=Jai}
The Hashtable contains value Vivek


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki