Tutorials Point


  Java Basics Examples
  Java Tutorial
  Java Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

Java Examples - Set View of Keys from HashtTable


previous next AddThis Social Bookmark Button


Problem Description:

How to set view of Keys from Java Hashtable?

Solution:

Following example uses keys() method to get Enumeration of Keys of the Hashtable.

import java.util.Enumeration;
import java.util.Hashtable;

public class Main {
   public static void main(String[] args) {
      Hashtable ht = new Hashtable();
      ht.put("1", "One");
      ht.put("2", "Two");
      ht.put("3", "Three");
      Enumeration e = ht.keys();
      while (e.hasMoreElements()){
         System.out.println(e.nextElement());
      }
   }
}

Result:

The above code sample will produce the following result.

3
2
1


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names