collect()
Object collect(Collector collector)
Collector collector
: collect()에 필요한 메소드를 정의해 놓은 인터페이스collect()
)에 필요한 메소드를 정의해 놓은 인터페이스핵심은 supplier()
& accumulator()
!!
supplier()
T
를 누적할 곳 == A
accumulator()
T
를 어떻게 누적할 건지, 누적 수행 작업combiner()
finisher()
T
-> A
-> R
로 최종변환characteristics()
Set
반환toArray()
- 매개변수 없는Student[] stuNames = studentStream.toArray(Student[]::new); //(O)
Student[] stuNames = studentStream.toArray(); //(X)
Student[] stuNames = (Student[])sudentStream.toArray(); //(O)
Object[] stuNames = studentStream.toArray(); //(O)
Object[]
를 반환한다.toArray(T[]::new)
- 매개변수 있는Student[] stuNames = studentStream.toArray(Student[]::new); //(O)
Student[] stuNames = studentStream.toArray(); //(X)
Student[] stuNames = (Student[])sudentStream.toArray(); //(O)
Object[] stuNames = studentStream.toArray(); //(O)
static counting()
import static java.util.Stream.Collectors.*;
로 했기 때문에 Collectors를 생략한 것Collectors.counting()
이어야 한다.summingInt()
maxBy()
, minBy()
reducing()
Collector reducing(T identity, BinaryOperator<T> op)
BinaryOperator<T> op
: accumulator, 누적작업Function<T,U> mapper
: T -> U 변환작업joining()