HashMap is a Map based collection class that is used for storing Key & value pairs
I would recommend you to go through my post 'How HashMap works in Java
'.
HashMap permits null values and null key.
I would recommend you to go through my post 'How HashMap works in Java
HashMap permits null values and null key.
The
HashMap performs the get and put operations in constant time.
HashMap
has two parameters that effects the Performance
a.
Capacity
b.
Load Factor
Capacity
capacity
is the number of buckets in the hash table.
Load
Factor
The
load factor is a measure of how full the hash table is allowed to get
before its capacity is automatically increased. By default Load
Factor for HashMap is 0.75.
For
Example let us assume
initial
capacity is 10 (I.e, Number Of Buckets)
Load
Factor is 0.75
Each
Bucket has the capacity to store 100 data items.
So
when all the items reached 0.75 * 100 * 10 = 750, then the internal
data structures rehashed and the Capacity(Number Of Buckets)
increases depends on implementation. The same logic applies in future
also.
HashMap
is not synchronized, So user has to taken care while performing put
kind of operations.
Collections.synchronizedMap
returns a synchronized map backed by the specified map.
Note
HashMap
implements Serializable and Cloneable interface.
public
class HashMap<K,V> extends AbstractMap<K,V>
implements
Map<K,V>, Cloneable, Serializable
No comments:
Post a Comment