|
|
How to create a Hash Table - JSP/Java
|
Views : 1031
|
|
Tagged in : JSP-Java
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
How to create a Hash Table
Hash table is generally used in searching applications. Hash table increases the search efficiency by creating a key corresponding to the values in the table.
// Create a hash table
Map map = new HashMap();
map = new TreeMap(); // sorted map
// Add key/value pairs to the map
map.put("x", new Integer(1));
map.put("y", new Integer(2));
map.put("z", new Integer(3));
// Get number of entries in map
int size = map.size(); // 2
// Adding an entry whose key exists in the map causes
// the new value to replace the old value
Object oldValue = map.put("x", new Integer(9)); // 1
// Remove an entry from the map and
// return the value of the removed entry
oldValue = map.remove("c"); // 3
// Iterate over all keys in the table
Iterator it = map.keySet().iterator();
while (it.hasNext()) {
// Retrieve key
Object key = it.next();
}
// Iterate over all values in table
it = map.values().iterator();
while (it.hasNext()) {
// Get value
Object value = it.next();
}
|
|
By Sanju, On - 2010-03-04 |
|
|
|