The Artima Developer Community
Sponsored Link

Java Buzz Forum
Java Collections example program Get Set view of Keys from Hashtable example

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.
Java Collections example program Get Set view of Keys from Hashtable example Posted: Mar 17, 2016 6:32 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by instanceof java.
Original Post: Java Collections example program Get Set view of Keys from Hashtable example
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 collection framework example program to get set view from hashtable

  • Set keySet()   This method used to get set view of the keys of hashtable
  •  Important note is that if any key is removed from set the original hashtable key also removed
  1. package com.setviewHashtable;
  2.  
  3. import java.util.Hashtable;

  4. import java.util.Enumeration;
  5. import java.util.Iterator;
  6. import java.util.Set;
  7.  
  8. public class HashtableExample{
  9.  
  10. public static void main(String[] args) {
  11.   
  12.  //create Hashtable object
  13.        Hashtable<String,String> hashtable = new Hashtable<String,String>();
  14.        
  15. //add key value pairs to Hashtable
  16. hashtable.put("1","Java Interview Questions");
  17. hashtable.put("2","Java Interview Programs");
  18. hashtable.put("3","Concept and example program");
  19. hashtable.put("4","Concept and interview Questions");
  20. hashtable.put("5","Java Quiz");
  21. hashtable.put("6","Real time examples");
  22.  
  23.  
  24.  Set st = hashtable.keySet();       
  25.  System.out.println("Set created from Hashtable Keys contains :");
  26. //iterate through the Set of keys
  27.  
  28.  Iterator itr = st.iterator();
  29.  while(itr.hasNext())
  30.  System.out.println(itr.next());
  31.            
  32.  st.remove("1");
  33.            
  34. System.out.println("Elements in hash table");
  35. Enumeration e=hashtable.keys();
  36.         
  37.  
  38.  while (e.hasMoreElements()) {
  39.         System.out.println(e.nextElement());
  40. }    

  41. }
  42.  
  43. }
     



Output:

  1. Set created from Hashtable Keys contains :
  2. 6
  3. 5
  4. 4
  5. 3
  6. 2
  7. 1
  8. Elements in hash table
  9. 6
  10. 5
  11. 4
  12. 3
  13. 2

Read: Java Collections example program Get Set view of Keys from Hashtable example

Topic: Remove key value pair from hashtable java example Previous Topic   Next Topic Topic: Why SpringBoot?

Sponsored Links



Google
  Web Artima.com   

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