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

Appearance settings

Latest commit

 

History

History
History
33 lines (28 loc) · 985 Bytes

File metadata and controls

33 lines (28 loc) · 985 Bytes
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"));
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.