Lambda Expressions
=> One issue with anonymous classes is that if the implementation of your anonymous class is very simple, such as an interface that contains only one method, then the syntax of anonymous classes may seem unwieldy and unclear. In these cases, you're usually trying to pass functionality as an argument to another method, such as what action should be taken when someone clicks a button. Lambda expressions enable you to do this, to treat functionality as method argument, or code as data.
=> 단일 메소드 클래스의 인스턴스를보다 간결하게 표현할 수 있는 기능.
Stream
=> Classes to support functional-style operations on streams of elements, such as map-reduce transformations on collections.
간단한 루프로 테스트
public class Main {
public static void main(String[] args) {
// Lambda Stream Test
List<Integer> list = new ArrayList<>();
IntStream.range(1, 5).forEach(i -> list.add(i));
list.forEach(System.out::println);
long cnt = list.stream().filter(e -> e > 2).count();
System.out.println("stream fileter&count test: " + cnt);
list.stream().filter(num -> num > 2).collect(Collectors.toList()).forEach(System.out::println);
}
}
결과
1
2
3
4
stream fileter&count test: 2
3
4
[ 출처 ] Document (Java Platform SE 8 ) - Oracle Help, Center 2020 . 02 . 26, https://docs.oracle.com/javase/8/docs/api/
'Java' 카테고리의 다른 글
[Java] 오버로딩 VS 오버라이드 (0) | 2020.12.27 |
---|---|
[Java] OOP의 특징 (0) | 2020.12.27 |
[Java] 객체지향언어 (0) | 2020.12.27 |
[Java] Lambda & Stream 3 (0) | 2020.02.26 |
[Java] Lambda & Stream 2 (0) | 2020.02.26 |