Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bc4fc56

Browse files
HashSet
1 parent 4973cb4 commit bc4fc56

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎src/Hashing2.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.HashMap;
2+
3+
public class Hashing2 {
4+
public static void main(String[] args) {
5+
6+
//declaration and initialization of Hashmap
7+
HashMap<String,Integer> map = new HashMap<>();
8+
9+
//put method to add key value pairs in the map
10+
map.put("China",150);
11+
map.put("India", 130);
12+
map.put("US",50);
13+
14+
//to print elements and its value inside the map
15+
System.out.println(map);
16+
17+
//get method to get a particular element and its value by its key
18+
int ans = map.get("China");
19+
System.out.println(ans);
20+
21+
//remove method to remove element by key
22+
map.remove("US");
23+
System.out.println(map);
24+
25+
//size method to get the size of the map
26+
System.out.println(map.size());
27+
}
28+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /