Insert Elements to HashMap

  1. put() - inserts the specified key/value mapping to the map.
  2. putAll() - inserts all the entries from specified map to this map
  3. putIfAbsent() - inserts the specified key/value mapping to the map if the specified key is not present in the map


\begin{lstlisting}
import java . util . HashMap ;
\par
class Main {
public stat...
...
System.out.println(''HashMap of numbers : '' + numbers);
}
}
\end{lstlisting}

Output


\begin{lstlisting}
HashMap of even numbers : { Six =6 , Four =4 , Two =2}
HashMap of numbers : { Six =6 , One =1 , Four =4 , Two =2}
\end{lstlisting}