How do I concatenate two IntStreams?
You're passing to concat
two Stream<IntStream>
, which won't work (you want a stream of integers). You need to give it two Stream<Integer>
:
List<String> strings72to200 = Stream
.concat(IntStream.range(72, 129).boxed(),
IntStream.range(132, 200).boxed())
.map(String::valueOf)
.collect(Collectors.toList());
And just a side note, if you intend to include 129
and 200
in the streams, you should use IntStream.rangeClosed
(end is exclusive)
You might just be looking for boxed
there to get a Stream<Integer>
and then concatenate :
List<String> strings72to200 = Stream.concat(
IntStream.range(72, 129).boxed(), // to convert to Stream<Integer>
IntStream.range(132, 200).boxed())
.map(String::valueOf) // replaced with method reference
.collect(Collectors.toList());
Edit: If you were to just get an IntStream
from the given inputs, you could have concatenated them as:
IntStream concatenated = Stream.of(
IntStream.range(72, 129),
IntStream.range(132, 200))
.flatMapToInt(Function.identity());
or simply
IntStream concatenated = IntStream.concat(
IntStream.range(72, 129),
IntStream.range(132, 200));