Is there a way to create 2 different objects for each element of a stream and collect them all at last?
For example,
if I have a List<String> stringList and have a class GoddClass with a default and a customConstructor, I want to create 2 objects in one stream and collect at last
stringList
.stream()
.map(GoddClass::new)
.addAnothrObject(GoddClass::customConstructor) // Not a valid line, Just to depict what is needed
.collect(Collectors.toList());
One stream might not be the right solution to achieve what I'm trying. But the question is out for experts.
flatMapflatMap(), when I had a steam mapping resulting another stream, or similar cases, but how do you fitflatMapin this scenarioList<GoddClass>with both those objects accepting a string as input and useflatMapto call it like...stream().flatMap(str -> method(str).stream()).collect....