FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
java-base/java-8future/src/test/java/FunctionTest.java at master · singgel/java-base · GitHub
singgel
/
java-base
Public
Notifications
You must be signed in to change notification settings
Fork
28
Star
39
Code
Issues
0
Pull requests
6
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
java-base
/
java-8future
/
src
/
test
/
java
/
FunctionTest.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (28 loc) · 985 Bytes
Breadcrumbs
java-base
/
java-8future
/
src
/
test
/
java
/
FunctionTest.java
Copy path
File metadata and controls
33 lines (28 loc) · 985 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
32
33
import
org
.
junit
.
Test
;
import
java
.
util
.
function
.
Function
;
import
java
.
util
.
stream
.
Stream
;
/**
* @author heks
* @description: TODO
* @date 2020/11/11
*/
public
class
FunctionTest
{
/**
* Function测试,function的作用是转换,将一个值转为另外一个值
*/
@
Test
public
void
test_Function
() {
//① 使用map方法,泛型的第一个参数是转换前的类型,第二个是转化后的类型
Function
<
String
,
Integer
>
function
=
new
Function
<
String
,
Integer
>() {
@
Override
public
Integer
apply
(
String
s
) {
return
s
.
length
();
//获取每个字符串的长度,并且返回
}
};
Stream
<
String
>
stream
=
Stream
.
of
(
"aaa"
,
"bbbbb"
,
"ccccccv"
);
Stream
<
Integer
>
stream1
=
stream
.
map
(
function
);
stream1
.
forEach
(
System
.
out
::
println
);
System
.
out
.
println
(
"********************"
);
System
.
out
.
println
(
function
.
apply
(
"heks"
));
}
}
Back
|
FazBrowse Home
|
New Git URL