[Java/자바] Stream 변환 표

반응형


Stream ➡ 기본형 Stream

From To 변환 메서드
Stream<T> IntStream
LongStream
DoubleStream
mapToInt(ToIntFunction<T> mapper)
MapToLong(ToLongFunction<T> mapper)
MapToDouble(ToDoubleFunction<T> mapper)

 


기본형 Stream ➡ Stream

From To 변환 메서드
IntStream
LongStream
DoubleStream

Stream<Integer>
Stream<Long>
Stream<Double>
boxed()
Stream<T> mapToObj(DoubleFunction<T> mapper)

 


기본형 Stream ➡ 기본형 Stream

From To 변환 메서드
IntStream
LongStream
DoubleStream
LongStream
DoubleStream
asLongStream()
asDoubleStream()

 


Stream ➡ 부분 Stream

From To 변환 메서드
Stream<T>
IntStream
Stream
IntStream
skip(long n)
limit(long maxSize)

 


두 개의 Stream ➡ Stream

From To 변환 메서드
Stream<T>, Stream<T> Stream<T> concat(Stream<T> a, Stream<T> b)
IntStream, IntStream IntStream concat(IntStream a, IntStream b)
LongStream, LongStream LongStream concat(LongStream a, LongStream b)
DoubleStream, DoubleStream DoubleStream concat(DoubleStream a, DoubleStream b)

 


Stream의 Stream ➡ Stream

From To 변환 메서드
Stream<Stream<T>> Stream<T> flatMap(Function mapper)
Stream<IntStream> IntStream flatMapToInt(Function mapper)
Stream<LongStream> LongStream flatMapToLong(Function mapper)
Stream<DoubleStream> DoubleStream flatMapToDouble(Function mapper)

 


Stream ➡ 병렬 Stream

From To 변환 메서드
Stream<T>
IntStream
LongStream
DoubleStream
Stream<T>
IntStream
LongStream
DoubleStream
parallel() // 스트림 -> 병렬 스트림
sequential // 병렬 스트림 -> 스트림

 


Stream ➡ Collection

From To 변환 메서드
Stream<T>
IntStream
LongStream
DoubleStream
Collection<T> collect(Collectors.toCollection(Supplierfactory)
List<T> collect(Collectors.toList())
Set<T> collect(Collectors.toSet())

 


Collection ➡ Stream

From To 변환 메서드
Collection<T>, List<T>, Set<T> Stream<T> stream()

 


Stream ➡ Map

From To 변환 메서드
Stream<T>
IntStream
LongStream
DoubleStream
Map<K, V> collect(Collectors.toMap(Function key, Function value)
collect(Collectors.toMap(Function key, Function value, BinaryOperator)
collect(Collectors.toMap(Function key, Function value, BinaryOperator merge, Supplier mapSupplier)

 


Stream ➡ 배열

From To 변환 메서드
Stream<T>

Object[] toArray()
T[] toArray(IntFunction<A[] generator)
IntStream
LongStream
DoubleStream
int[]
long[]
double[]
toArray()