Hashtable stores key/value pairs in a hash table. When using a Hashtable, you specify an object that is used as a key, and the value that you want linked to that key. The key is then hashed, and the resulting hash code is used as the index at which the value is stored within the table.
Hashtable<Integer, String> hashtable = new Hashtable<Integer, String>();
here the key is an integer and value is string datatype.
Ex: hashtable.put(1, "Apple");
similarly,
Hashtable<String, String> hashtable = new Hashtable<String, String>();
Ex: hashtable.put("IN", "INDIA");
here the key and value both are strings.
functions:
hashtable.clear();
it clears the all data with in hashtable.
hashtable.isEmpty();
it returns a boolean value, based on the hashtable is empty or not.
hashtable.size();
it returns how many records are available in hashtable.
hashtable.containsKey("key");
it returns a boolean value. it checks the key is existed or not in hashtable.
hashtable.containsValue("value");
it returns a boolean value. it checks the value is existed or not in hashtable.
hashtable.get("key");
it returns the value based on given key.
hashtable.remove("key");
it removes the record based on given key. it returns the deleted key value.
hashtable.put("key", "value");
it returns the previous value of given key.
hashtable.putAll(treeMap);
it sets all treeMap values to hashtable.
Set<String> set = hashtable.keySet()
it returns the set of keys in hashtable.
Enumeration<String> enumeration = hashtable.keys();
it returns the set of keys in hashtable.
Enjoy and Happy Coding....
Hashtable<Integer, String> hashtable = new Hashtable<Integer, String>();
here the key is an integer and value is string datatype.
Ex: hashtable.put(1, "Apple");
similarly,
Hashtable<String, String> hashtable = new Hashtable<String, String>();
Ex: hashtable.put("IN", "INDIA");
here the key and value both are strings.
functions:
hashtable.clear();
it clears the all data with in hashtable.
hashtable.isEmpty();
it returns a boolean value, based on the hashtable is empty or not.
hashtable.size();
it returns how many records are available in hashtable.
hashtable.containsKey("key");
it returns a boolean value. it checks the key is existed or not in hashtable.
hashtable.containsValue("value");
it returns a boolean value. it checks the value is existed or not in hashtable.
hashtable.get("key");
it returns the value based on given key.
hashtable.remove("key");
it removes the record based on given key. it returns the deleted key value.
hashtable.put("key", "value");
it returns the previous value of given key.
hashtable.putAll(treeMap);
it sets all treeMap values to hashtable.
Set<String> set = hashtable.keySet()
it returns the set of keys in hashtable.
Enumeration<String> enumeration = hashtable.keys();
it returns the set of keys in hashtable.
Enjoy and Happy Coding....
No comments:
Post a Comment