FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java_upgrade/src/main/java/lambdas/MapDemo.java at master · amhtech/java_upgrade · GitHub
amhtech
/
java_upgrade
Public
forked from
kousen/java_upgrade
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java_upgrade
/
src
/
main
/
java
/
lambdas
/
MapDemo.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (26 loc) · 927 Bytes
Breadcrumbs
java_upgrade
/
src
/
main
/
java
/
lambdas
/
MapDemo.java
Copy path
File metadata and controls
31 lines (26 loc) · 927 Bytes
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
package
lambdas
;
import
java
.
util
.
Comparator
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
Map
;
public
class
MapDemo
{
public
static
void
main
(
String
[]
args
) {
Map
<
String
,
Integer
>
map
=
new
HashMap
<>();
map
.
put
(
"c"
,
2
);
map
.
put
(
"a"
,
1
);
map
.
put
(
"d"
,
3
);
map
.
put
(
"b"
,
2
);
map
.
computeIfAbsent
(
"e"
,
String
::
length
);
map
.
computeIfAbsent
(
"b"
,
String
::
length
);
map
.
computeIfPresent
(
"b"
, (
k
,
v
) -> {
System
.
out
.
printf
(
"k = %s,v = %d%n"
,
k
,
v
);
return
v
*
2
;
});
map
.
forEach
((
k
,
v
) ->
System
.
out
.
println
(
k
+
" maps to "
+
v
));
map
.
entrySet
().
stream
()
.
sorted
(
Map
.
Entry
.
comparingByKey
(
Comparator
.
reverseOrder
()))
.
forEach
(
System
.
out
::
println
);
map
.
entrySet
().
stream
()
.
sorted
(
Map
.
Entry
.
comparingByValue
())
.
forEach
(
System
.
out
::
println
);
}
}
Back
|
FazBrowse Home
|
New Git URL