FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
All-Java-Works/HashMapPart1.java at master · shakiz/All-Java-Works · GitHub
shakiz
/
All-Java-Works
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
All-Java-Works
/
HashMapPart1.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (45 loc) · 1.5 KB
Breadcrumbs
All-Java-Works
/
HashMapPart1.java
Copy path
File metadata and controls
51 lines (45 loc) · 1.5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
50
51
package
hashmap
.
part1
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
Scanner
;
//advantages of hashmap
/*
1.If no synchronization is needed
2.fast to insert ,search or delete
3.Updated version of hashtable
4.Stores values against key and support only one null key and multiple null values
*/
public
class
HashMapPart1
{
public
static
void
main
(
String
[]
args
) {
Scanner
scan
=
new
Scanner
(
System
.
in
);
HashMap
<
String
,
Long
>
map
=
new
HashMap
<>();
print
(
map
);
System
.
out
.
println
(
"Enter size of phonebook:"
);
int
size
=
scan
.
nextInt
();
for
(
int
i
=
0
;
i
<
size
;
i
++){
System
.
out
.
println
(
"Key:"
);
String
key
=
scan
.
next
();
System
.
out
.
println
(
"Value:"
);
long
value
=
scan
.
nextLong
();
map
.
put
(
key
,
value
);
}
print
(
map
);
System
.
out
.
println
(
"Enter key to get value:"
);
String
getKey
=
scan
.
next
();
if
(
map
.
containsKey
(
getKey
)){
long
getValue
=
map
.
get
(
getKey
);
System
.
out
.
println
(
"The value for key : "
+
getKey
+
" is : "
+
getValue
);
}
else
{
System
.
out
.
println
(
"No results found."
);
}
System
.
out
.
println
(
"Size of the map or phonebook:"
+
map
.
size
());
}
public
static
void
print
(
HashMap
<
String
,
Long
>
map
){
if
(
map
.
isEmpty
()){
System
.
out
.
println
(
"PhoneBook is empty."
);
}
else
{
System
.
out
.
println
(
map
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL