Please disable adblock to view this page.

← Go home

Unordered Data using HashMap in Java


May 1, 2017
Published By : Pratik Kataria
Categorised in:

Understanding through Code

import java.util.HashMap;
import java.util.Map;

public class HashMapDemo {
	public static void main( String[] args ){
		Map<String, String> map = new HashMap<>();

		map.put("India", "First");
		map.put("US", "Second");
		map.put("Canada", "Third");

		map.put("Russia", "Fourth");

		String mapString = map.get("US");
		System.out.println("The US stands at: " +mapString);



  • {Canada=Third, US=Second, India=First}
  • {Canada=Third, US=Second, India=First, Russia=Fourth}
  • The US stands at: Second
  • Second


  • HashMap is unordered data collection.
  • HashMap is implementation of Map. Just like ArrayList is an implementation of List.
  • Maps are in Key, Value pairs.
  • You can look up an item in HashMap with the help of Key.

Pratik Kataria is currently learning Springboot and Hibernate.
Technologies known and worked on: C/C++, Java, Python, JavaScript, HTML, CSS, WordPress, Angular, Ionic, MongoDB, SQL and Android.
Softwares known and worked on: Adobe Photoshop, Adobe Illustrator and Adobe After Effects.