Initializing HashMap in Java

Map<String,String> paramMap = new HashMap<>();

I tried to use HashMap when I read a list of numbers from csv and want to proceed to the next process only for unique ones, but ...

Map<String, String> paramMap = null; while((record = reader.readNext()) != null){ if(paramMap.get(record[0]) != null { continue; } paramMap.put(record[0],record[0]); Next processing }

Then, an error occurs in nullpointer.exception in the part of paramMap.get It's easy to know what to do

Map<String, String> paramMap = null;

With this, pramMap has not been initialized, and if you call it, a null reference will occur. Here

Map<String,String> paramMap = new HashMap<>();

Then it works fine

I would be grateful if you could tell me if there is another good way to retrieve unique records ^ _ ^

Recommended Posts

Initializing HashMap in Java
Partization in Java
Java HashMap class
Changes in Java 11
Rock-paper-scissors in Java
Pi in Java
FizzBuzz in Java
[java] sort in list
Read JSON in Java
Interpreter implementation in Java
Make Blackjack in Java
Rock-paper-scissors app in Java
NVL-ish guy in Java
Combine arrays in Java
"Hello World" in Java
Callable Interface in Java
Deep dive into how HashMap works in Java
Comments in Java source
Azure functions in java
Format XML in Java
Boyer-Moore implementation in Java
Hello World in Java
Use OpenCV in Java
webApi memorandum in java
Type determination in Java
Ping commands in Java
[Java] Understand in 10 minutes! Associative array and HashMap
Various threads in java
Heapsort implementation (in java)
Zabbix API in Java
ASCII art in Java
Compare Lists in Java
POST JSON in Java
Express failure in Java
Create JSON in Java
Date manipulation in Java 8
What's new in Java 8
Use PreparedStatement in Java
What's new in Java 9,10,11
Parallel execution in Java
A note for Initializing Fields in the Java tutorial
Try using RocksDB in Java
Read binary files in Java 1
Avoid Yubaba's error in Java
Get EXIF information in Java
Save Java PDF in Excel
[Neta] Sleep Sort in Java
Edit ini in Java: ini4j
Java history in this world
Let Java segfault in 6 lines
Try calling JavaScript in Java
Try developing Spresense in Java (1)
Try functional type in Java! ①
I made roulette in Java.
Create hyperlinks in Java PowerPoint
Implement two-step verification in Java
Refactoring: Make Blackjack in Java
Write flyway callbacks in Java
Topic Analysis (LDA) in Java
Importing Excel data in Java 2
NEologd preprocessing in Java neologdn-java