-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hashmap.java
49 lines (38 loc) · 1006 Bytes
/
Hashmap.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package core;
import java.util.HashMap;
public class Hashmap {
public static void main(String[] args) {
HashMap<String, String> city = new HashMap<String, String>();
// Add keys and values (State, City)
city.put("Maharashtra", "Pune");
city.put("Telangana","Hydrabad");
city.put("Tamilnadu","Chennai");
city.put("Panjab","Amritsar");
city.put("England", "London");
city.put("Bangal", "Kolkata");
System.out.println(city);
//Access an Item
System.out.println(city.get("Panjab"));
//Remove an Item
city.remove("England");
System.out.println(city);
//HashMap Size
System.out.println(city.size());
//Loop Through a HashMap
//Get Keys
for(String i:city.keySet())
{
System.out.println(i);
}
//Get Values
for(String i:city.values())
{
System.out.println(i);
}
//Get Keys and Values
for(String i:city.keySet())
{
System.out.println("Key="+i+","+"Values="+city.get(i));
}
}
}