Hashtable
is a generic type. You should use the corresponding parameterized type by passing the type arguments, while using it. Just using the class name Hashtable
is raw type, and is discouraged, except in some places, where you have to use them.
So, you would instantiate the object as:
Hashtable<String, String> nu = new Hashtable<String, String>();
However, you should also avoid using a Hashtable
. The reason being, every operation of Hashtable
is synchronized, which you really don't need. That unnecessarily makes the execution slow. Better to use a HashMap
instead. You can use it like this:
Map<String, String> map = new HashMap<String, String>();
Map<String, String> map2 = new HashMap<>(); // Valid from Java 7 onwards
Apart from that, you don't need to create a new String
object using new String(...)
, while adding them to the map. Just use string literals, so as t avoid unnecessary object creation:
nu.put("postmaster", "admin"); // Will work fine
Related: