If many entries are to be made into a Hashtable, creating it with a sufficiently large capacity may allow the entries to be inserted more efficiently than letting it perform automatic rehashing as needed to grow the table. This example creates a hashtable of Htable. It uses the names of the Htable as keys:
Code:
Hashtable Htable = new Hashtable();
Htable.put("Eleven", new Integer(11));
Htable.put("Tweleve", new Integer(12));
Htable.put("Thirteen", new Integer(13));
Now if you want to retrieve the number then it is necessary to make use of the code below:
Code:
Integer num = (Integer)Htable.get("twelve");
if (num != null)
{
System.out.println("twelve = " + num);
}
Bookmarks