Coding⏱️ 2 min read📅 2026-05-31

How to Fix: java: HashMap<String, int> not working

HashMap with String key and int value works but not with Integer type.

Quick Answer: The issue is that in Java, the primitive data types like int are not automatically boxed to their corresponding wrapper classes. So, when you use HashMap, it's trying to store an int primitive, which doesn't work. Using HashMap fixes this by using the Integer class as the wrapper.

The problem you're facing is due to the fact that Java is case-sensitive. In your code, you've used lowercase 'i' in HashMap, whereas in the correct syntax, it's uppercase 'I'. This discrepancy causes the compiler to throw an error.

💡 Why You Are Getting This Error

  • [Cause]

🛠️ Step-by-Step Verified Fixes

Method 1: Correct Syntax

  1. Step 1: Replace all instances of 'i' with 'I' in your HashMap declaration.

Method 2: Understanding Case Sensitivity

  1. Step 1: Be aware that Java is case-sensitive, meaning 'int' and 'Integer' are two different data types.

✨ Wrapping Up

By making these simple changes, you can resolve the issue and successfully use HashMap with int values in your Java program.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions