Skip to main content

What is the significance of load factor in HashMap?


An instance of HashMap has two parameters that affect its performance: initial capacity and load factor. The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created. The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the hash table is rehashed (that is, internal data structures are rebuilt) so that the hash table has approximately twice the number of buckets.

As a general rule, the default load factor (.75) offers a good tradeoff between time and space costs. Higher values decrease the space overhead but increase the lookup cost (reflected in most of the operations of the HashMap class, including get and put). The expected number of entries in the map and its load factor should be taken into account when setting its initial capacity, so as to minimize the number of rehash operations. If the initial capacity is greater than the maximum number of entries divided by the load factor, no rehash operations will ever occur.

Full Documentation :
 
http://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html

Comments

Popular posts from this blog

Replace Non ASCII Characters in a File

Replace Non ASCII Characters in a File ? package com.pukhraj.blog; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; public class ReplaceNonAsciiCharacters {     public static void main(String args[]) {         String inputFileName = "D:/input_file_name.txt";         String outputFileName = "D:/output_file_name.txt";         try {         // Read the content from the input file using BufferedReader object.             BufferedReader in = new BufferedReader(new FileReader(inputFileName));                         // Write the content to the output file using BufferedWriter object.             BufferedWriter out = new BufferedWriter(new FileWriter(outputFileName));         ...

Heartfelt Wishes & Quotes for Special Occasions | Make Every Moment Memorable

  Introduction Special occasions are milestones in our lives that deserve to be celebrated with joy, love, and heartfelt messages. Whether it’s a birthday, wedding, or holiday, sharing wishes and quotes can add a personal touch, making these moments even more memorable. This article delves into the significance of wishes and quotes, offering a curated collection for various special occasions to help you convey your sentiments perfectly. Why Wishes and Quotes Matter Wishes and quotes are more than just words; they hold the power to uplift spirits, convey deep emotions, and strengthen relationships. Sending a thoughtful message on a special day shows that you care, helping to build stronger connections with those who matter most. Whether you’re looking to inspire, amuse, or simply spread joy, the right words can leave a lasting impact. Types of Special Occasions Special occasions vary widely, from personal milestones like birthdays and anniversaries to cultural and religious celebrat...
How to check a string starts with numeric number? String str = "123abcd"; boolean isStartWithDigit = Character.isDigit(s.charAt(0)); System.out.println("isStartWithDigit: "+isStartWithDigit); How to get first numeric value from a string in java?  Matcher matcher = Pattern.compile("\\d+").matcher(titleStr); if(matcher.find()) { System.out.println(matcher.group()); }; How to check if a String contains another String in a case insensitive manner in Java? Solution 1: String str = "I am Java Developer"; String test = "java"; Boolean bool = str.toLowerCase().contains(test.toLowerCase()); System.out.println(bool); Solution 2: org.apache.commons.lang3.StringUtils.containsIgnoreCase("AbBaCca", "bac"); Solution 3: Pattern.compile(Pattern.quote(s2), Pattern.CASE_INSENSITIVE).matcher(s1).find();