Hash table
is a data structure that provides quick insert operations and find operations. The first time you touch a hash table, its advantages are unbelievable. Regardless of how much data is in the hash table,
Insertions and deletions (sometimes including side-by-sides) require only a time level of 0 (1) to approximate the constant. In fact, this only requires a few machine instructions.
For the one by one of people who use the hash table, it's a matter of a moment. Hash tables operate very quickly, in computer programs, if you need to find thousands of records in a second, usually
Hash tables using hash tables, such as the spelling checker, are significantly faster than trees, and tree operations typically require an O (N) time level. A hash table is not only fast, it is also relatively easy to implement programmatically.
Hash table also has some shortcomings it is based on an array, the array is difficult to expand after the creation of some hash table is basically filled with the performance degradation is very serious, so the program must be clear
How much data will be stored in the table (or ready to periodically transfer the data to a larger hash table, which is a time-consuming process).
Also, there is no easy way to traverse data items in a table in any order, such as from small to large. If you need this capability, you can only select other data structures.
However, if you do not need to traverse the data sequentially, the well can predict the size of the data in advance. Then the hash table is unmatched in terms of speed and ease-of-use.
Hashtable (hash table)
In this example, the use of the Hashtabledemo and enumeration classes is illustrated
Import java.util.Enumeration;
Import java.util.Hashtable;
public class Hashtabledemo {
public static void Main (string[] args) {
Hashtable<integer,string>table=new hashtable<integer,string> ();
Table.put (New Integer ("1"), "one");
Table.put (New Integer ("2"), "both");
Table.put (New Integer ("3"), "three");
Table.put (New Integer ("4"), "four");
System.out.println ("Traverse Hashtable with For Loop");
for (int i=1;i<=table.size (); i++) {
System.out.print (String) table.get (i) + "");
}
System.out.println ("\ n Traverse Hashtable with enumeration");
Enumeration<string>enu =table.elements ();
while (Enu.hasmoreelements ()) {
System.out.print (enu.nextelement () + "");
}
}
}
Java Collection Class Hash table