The Artima Developer Community
Sponsored Link

Java Buzz Forum
Check particular value exist in hashtable

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
instanceof java

Posts: 576
Nickname: instanceof
Registered: Jan, 2015

instanceof java is a java related one.
Check particular value exist in hashtable Posted: Mar 16, 2016 2:21 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Check particular value exist in hashtable
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java

Advertisement
1.Basic java example program to check particular value exist in hashtable
  • boolean contains(Object value)   This method used to check  particular value exist in hashtable

  1. package com.CheckElelemtHashtable;
  2.  
  3. import java.util.Hashtable;

  4. import java.util.Enumeration;
  5.  
  6. public class HashtableExample{
  7.  
  8. public static void main(String[] args) {
  9.   
  10.  //create Hashtable object
  11.        Hashtable<String,String> hashtable = new Hashtable<String,String>();
  12.        
  13. //add key value pairs to Hashtable
  14. hashtable.put("1","Java Interview Questions");
  15. hashtable.put("2","Java Interview Programs");
  16. hashtable.put("3","Concept and exampe program");
  17. hashtable.put("4","Concept and interview Questions");
  18. hashtable.put("5","Java Quiz");
  19. hashtable.put("6","Real time examples");
  20.  
  21.  /*
  22.  To check whether a particular value exists in Hashtable we need to use
  23.  boolean containsKey(Object value) method of Hashtable class.
  24. if the Hashtable contains mapping for specified value It returns true
  25. otherwise returns false.
  26. */
  27.        
  28.  boolean isExists = hashtable.contains("Java Quiz");
  29.  System.out.println("Java Quiz exists in Hashtable ? : " + isExists);

  30. System.out.println("Hashtable values : ");
  31.  
  32. Enumeration e=hashtable.elements();
  33.           
  34.  
  35.            
  36. // display search result
  37.  while (e.hasMoreElements()) {
  38.         System.out.println(e.nextElement());
  39. }    

  40. }
  41.  
  42. }
     



Output:

  1. Java Quiz exists in Hashtable ? : true
  2. Hashtable values : 
  3. Real time examples
  4. Java Quiz
  5. Concept and interview Questions
  6. Concept and exampe program
  7. Java Interview Programs
  8. Java Interview Questions

Read: Check particular value exist in hashtable

Topic: Remove all elements LinkedHashSet example Previous Topic   Next Topic Topic: Java Tutorial : Java String (lastIndexOf(String str) method)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use