Hashtable

Create Java Hashtable from HashMap example

Want to learn quickly?
Try one of the many quizzes. More than Java 400 questions with detailed answers.

1 Comment

  • Readers,

    If you’re trying to add a hashmap to a hashtable and if suppose the hashmap contains NULL values for atleast a key, then putAll method will throw a Null Pointer Exception.

    Example:

    HashMap sampleHashmap = new HashMap();
    sampleHashMap.put(“key1”, null);

    Hashtable sampleHashtable = new Hashtable();
    sampleHashtable.putAll(sampleHashMap);

    The above code will throw a NullPointerException.

    Regards,
    Akshay Sahu ([email protected])

Sponsors

Facebook Fans