Which is better option to use:
HashMapwith initial size:HashMap hm = new HashMap(10);orHashMapwithout initial size:HashMap hm = new HashMap()?
And why?
Also what is loadfactor and modcount in HashMap's property?
When I debug my code in eclipse and look at value of HashMap it shows a property named loadfactor with a value of 0.75 and a property named modcount with a value of 3.
Where i use hashmap in my code:-
I'm developing a communication application you can a say a chat application. in which i store all send/received messages in HashMap. Now as i cant assume how many messages will a user will send/receive i declare a hashmap without initial capacity. What i have written is
Map<String, Map<String, List<String>>> usersMessagesMap = new HashMap<String, Map<String,List<String>>>(); if i use it with initial capacity of 100 or higher will it effect the code?
hashCodefunction will be uniformly distributed (unless you write one by yourself). If you know that the default capacity is much smaller than the keyset size, I'd recommend using a higher initial capacity to reduce rehashing.