-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashmap.java
More file actions
31 lines (30 loc) · 1.43 KB
/
Copy pathhashmap.java
File metadata and controls
31 lines (30 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package HashMap;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
//public class hashmap {
// public static void main(String[] args) {
//// ----------------------------Default Constructor------------------------------------
// java.util.HashMap<Integer, String> hmap1 = new java.util.HashMap<>();
// java.util.HashMap<Integer, String> hmap2 = new java.util.HashMap<>();
//// -----------------------------Add Ele by using Put method-------------------------
// hmap1.put(1, "Sudhu");
// hmap1.put(2, "Gill $");
// hmap1.put(3, "Vishal");
// hmap1.put(4, "Shubh");
// hmap1.put(5, "Tarun");
// System.out.println(hmap1);
//// -----------------------------Retrieve Ele by get method---------------------------
// System.out.println(hmap1.get(1));
//// -----------------------------Retrieve Ele by getorDefault method----------------
// System.out.println(hmap1.getOrDefault(5, "Not Exist"));
// -----------------------------Getting only values------------------------------------
// System.out.println(hmap1.values());
// Iterator<hashmap.Entry<Integer, String>> itr = hmap1.entrySet().iterator();
// while(itr.hasNext()) {
// hashmap.Entry<Integer, String> entry = itr.next();
// System.out.println("Key: " + entry.getKey() +", Value: " + entry.getValue() );
// }
//
// }
//}