-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from saurabh12nxf/hashmap-example-#43
Hashmap example #43
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |