how to optimize hashmap by setting initialsize and loadFactor

99 Views Asked by At

I am getting data from Db and storing into Hashmap with 10,000 entries and some times I dont know the size of resultSet. I want to optimize the HashMap. so that it didn't reHash the entire hashmap by setting loadFactor and IntialSize. I know that in Consturctor of HashMap as HashMap(IntialSize,LoadFactor). can we set after getting the size of resultSet.

Same code like this.

HashMap<String, UserDetails> userHashMap = new HashMap<String, UserDetails>();
while (rs.next()) {
    String Id = rs.getString("id");
    String Name = rs.getString("name");
    String address = rs.getString("address");
    UserDetails userEntries = new UserDetails(id, name, addresss);

    userHashMap.put(Id, UserEntries);
}
return UserHashMap;
0

There are 0 best solutions below