Search This Blog

Friday, December 28, 2012

Java Hashtable Example

import java.util.*;
public class MainClass {
  public static void main(String args[]) {
    Hashtable columnValues = new Hashtable();
    columnValues.put("Tokyo", "Japan");
    columnValues.put("Beijing", "China");
    columnValues.put("Bangkok", "Thailand");
    String city = "Beijing";
    String country = (String) columnValues.get(city);
    if (country != null)
      System.out.println(city + " is located in " + country);  //Beijing is located in China
    else
      System.out.println(city + " is not located in the hashtable");
  }
}

No comments:

Post a Comment