hashtable in java hashtable example in java hash table in java hash table implementation in java hash table in java example hashtable in java example code hashtable example in java code
Hash Table :
Hash table is one
of the sub class of Dictionary, so that all the methods of Dictionary
class
inherited into Hash Table class. Hash table class organizes the data in the
form of
(key, value) pairs by following Hashing mechanism.
Since it follows hashing mechanism as a java programmer we
cannot determine in
what order HashTable class object displays the data i.e;
undetermined form. The
functionality of HashTable is more or less similar to
HashMap but HashTable belongs to
synchronized and it never allows null values
for (key, value) pairs. Whereas HashMap
Class object belongs to
Non-synchronized and it allows null values for (key, value) pair.
Creating Hash Table is nothing but creating an object
HashTable class object.
For Example:
HashTable ht=new
HashTable();
Profile ofHashTable Class :
1)
HashTable()
2)
HashTable(int)
3)
HashTable(int size,float fillratio)
Limitations of HashTable :
If we develop any application we are able
to maintain user defined data in the form of (key,
value) pair and we are
unable to develop the following
a)
Unable to read the data from Properties file
/resource bundle file.
b)
Unable to read the data from environmental
variables.
c)
Unable to develop flexible application.
The Following Program which the concept of
HashTable :
import
java.util.*;
class htable
{
Public
static void main(String args[])
{
HashTable
ht=new HashTable();
//add the
data ( key,value) as(state ,capital) to ht
ht.put(“AP”,”HYD”);
ht.put(“TN”,”CHN”);
ht.put(“KT”,”BANG”);
Enumeration
e=ht.keys();
While(e.hasMoreElements())
{
Object
kobj=e.nextElement();
Object
vobj=ht.get(kobj);
System.out.println(kobj+”-----------“+vobj);
}
If(args.length==0)
{
System.out.println(“PLZ ENTER THE STATE”);
}
else
{
String
state=args[]0].toUpperCase();
Object
cap=ht.get(state);
If(cap!=null)
{
System.out.println(cap+”is capital of “+state);
}
else
{
System.out.println(“Capital is not found”);
}
}
}
Data Extraction Interfaces are as follows :
Data Extraction Interfaces are as follows :
1- D and 2-D Collection Frame work classes are
No comments:
Post a Comment