Posts

Showing posts with the label Hashmap

Map interface with implementation classes

Map interface stores elements in the form of key-value pairs in java. If the key is provided then its corresponding value can be obtained. Of course, the keys should have unique values. Map interface implemented classes are, HashMap HashTable LinkedHashMap TreeMap Methods of Map implemented classes: value put(key, value) : This method stores key-value pairs. value get(Object key) : This method returns corresponding value when key is given. If the key does not have a value associated with it, then it returns null. Set<K> keySet() : This method, when applied on a map converts it into a Set where only keys will be stored. Collection<V> values() : This method, when applied on a HashMap objects returns all the values of the HashMap into Collection objects. value remove(Object key) : This method removes the key and corresponding value from the map. void clear() : This method removes all the key-value pairs. boolean isEmpty() : This met...