Search code examples
javahashtable

Is this correct usage of a hashtable in Java


package datastrcutures;
import java.util.*;

public class java_hashtable {
      public static void ratingofcity() {
           Hashtable CityRating = new Hashtable();
           CityRating.put("New York", "8");
           CityRating.put("Sandton", "9");
      }

}

Solution

  • I think you have a typo there, your object type has to be Hashtable instead of Hasttable And you should use Java Generics

    Instantiate your hash table object like this:

    Hashtable<String, String> cityRating = new Hashtable<String, String>();
    

    And as Java naming convention I would suggest having your object name start with a lower case letter.