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 ("\n Newly created HashMap status : " +hash1Map );
24
+ System .out .println ("\n Size of HashMap / No of elements : " +hash1Map .size ());
25
+ System .out .println ("\n Check key exits in hashMap : " +hash1Map .containsKey (null ));
26
+ System .out .println ("\n Check value exits in hashMap : " +hash1Map .containsValue (9999 ));
27
+ System .out .println ("\n Check value -1 exits in hashMap : " +hash1Map .containsValue (-1 ));
28
+ System .out .println ("\n Get 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 ("\n Key : " +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 ("\n Access element using key : " +hash1Map .get (null ));
41
+
42
+ }
43
+
44
+ }
0 commit comments