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 50a5aa7

Browse files
basics of HashMaps with Stream API.
1 parent 808fba5 commit 50a5aa7

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.udemy.dsapart1.hashmaps;
2+
import java.util.HashMap;
3+
import java.util.Map;
4+
import java.util.Map.Entry;
5+
import java.util.Set;
6+
7+
/**
8+
*
9+
* This class act as driver code to start execution via main() for HashMap
10+
* examples.
11+
*
12+
*/
13+
public class TestDriverFromHashMaps {
14+
15+
public static void main(String[] args) {
16+
Map hash1Map=new HashMap<>();
17+
hash1Map.put("clr","Value-AL");
18+
hash1Map.put("01","IBM");
19+
hash1Map.put(null,500);
20+
hash1Map.put(2,"(*(#*($*");
21+
hash1Map.put(3.99,9999);
22+
hash1Map.put(null,-777);
23+
System.out.println("\nNewly created HashMap status : "+hash1Map);
24+
System.out.println("\nSize of HashMap / No of elements : "+hash1Map.size());
25+
System.out.println("\nCheck key exits in hashMap : "+hash1Map.containsKey(null));
26+
System.out.println("\nCheck value exits in hashMap : "+hash1Map.containsValue(9999));
27+
System.out.println("\nCheck value -1 exits in hashMap : "+hash1Map.containsValue(-1));
28+
System.out.println("\nGet hashcode of hashMap : "+hash1Map.hashCode());
29+
30+
//Iteration over hashMap.
31+
Set<Entry> entrySetRef=hash1Map.entrySet();
32+
//Using filter on-top of collections
33+
entrySetRef.parallelStream()
34+
.filter(t->t.getKey()!=null)
35+
.forEach(t ->
36+
System.out.println("\nKey : "+t.getKey()+"=>hashcode : "+t.getKey().hashCode()+" --> Value : "+t.getValue()+" ")
37+
);
38+
39+
//Time complexity is constant - O(1) - to access element
40+
System.out.println("\nAccess element using key : "+hash1Map.get(null));
41+
42+
}
43+
44+
}

0 commit comments

Comments
(0)

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