I have created a hash map that the users input the key and the value. i want to be able to change the value of the hash map if a specific key is entered.. Now, either the last point was poorly worded (i.e. you want to update the set associated with the key) or you really want to update the key itself, in which case you'd probably have to just remove it and add a new entry.. On this document we will be showing a java example on how to use the replace() method of hashmap class.basically this method is being used to insert a new a new key-value mapping to the hashmap object..
The javadoc explains it. note: great care must be exercised if mutable objects are used as map keys. the behavior of a map is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is a key in the map.. If there are no key-value mapping present in the map then this function returns true else false. set keyset(): it returns the set of the keys fetched from the map. value put(key k, value v): inserts key value mapping into the map. used in the above example. int size(): returns the size of the map – number of key-value mappings.. Java map interface. a map contains values on the basis of key, i.e. key and value pair. each key and value pair is known as an entry. a map contains unique keys. a map is useful if you have to search, update or delete elements on the basis of a key. java map hierarchy.
No comments:
Post a Comment