Skip to content

Commit

Permalink
Merge pull request #125 from saurabh12nxf/hashmap-example-#43
Browse files Browse the repository at this point in the history
Hashmap example #43
  • Loading branch information
abhishektripathi66 authored Feb 21, 2025
2 parents 955d3ae + ba306b7 commit 496bc83
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Binary file added src/Data Structures/HashMap/HashMapExample.class
Binary file not shown.
30 changes: 30 additions & 0 deletions src/Data Structures/HashMap/HashMapExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import java.util.HashMap;

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

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

map.put("Apple", 10);
map.put("Banana", 20);
map.put("Orange", 30);


System.out.println("Value for key 'Apple': " + map.get("Apple"));


map.remove("Banana");
System.out.println("HashMap after removing 'Banana': " + map);


System.out.println("Iterating over HashMap:");
for (String key : map.keySet()) {
System.out.println("Key: " + key + ", Value: " + map.get(key));
}

System.out.println("Contains key 'Orange': " + map.containsKey("Orange"));
System.out.println("Contains value 30: " + map.containsValue(30));
System.out.println("Contains key 'Banana': " + map.containsKey("Banana"));
System.out.println("Contains value 20: " + map.containsValue(20));
}
}

0 comments on commit 496bc83

Please sign in to comment.