I have a question regarding Java streams. Let's say I have a stream of Object and I'd like to map each of these objects to multiple objects. For example something like
IntStream.range(0, 10).map(x -> (x, x*x, -x)) //...
Here I want to map each value to the same value, its square and the same value with opposite sign. I couldn't find any stream operation to do that. I was wondering if it would be better to map each object x to a custom object that has those fields, or maybe collect each value into intermediate Map (or any data structure).
I think that in terms of memory it could be better to create a custom object, but maybe I'm wrong.
In terms of design correctness and code clarity, which solution would be better? Or maybe there are more elegant solutions that I'm not aware of?
IntStream.range(0, 10).mapToObj(x -> new int[] {x, x*x, -x}).