Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Hashmap in JAVA
  • Loading branch information
anshul17024 authored Oct 2, 2019
commit c5be7d7be96a512c04e6b4956b8f8dd9623e205e
44 changes: 44 additions & 0 deletions Data Structures/Hash Map/hashmap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Java program to illustrate
// Java.util.HashMap

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

public class GFG {
public static void main(String[] args)
{

HashMap<String, Integer> map
= new HashMap<>();

print(map);
map.put("vishal", 10);
map.put("sachin", 30);
map.put("vaibhav", 20);

System.out.println("Size of map is:- "
+ map.size());

print(map);
if (map.containsKey("vishal")) {
Integer a = map.get("vishal");
System.out.println("value for key"
+ " \"vishal\" is:- "
+ a);
}

map.clear();
print(map);
}

public static void print(Map<String, Integer> map)
{
if (map.isEmpty()) {
System.out.println("map is empty");
}

else {
System.out.println(map);
}
}
}