N
N
NEO not chosen2019-07-19 15:45:50
Java
NEO not chosen, 2019-07-19 15:45:50

Java Stream API how to implement?

I came up with a task for myself (to fix the topic stream), and I myself can’t solve it.
I will describe the problem rather abstractly, the main thing here is not the code, but the solution method.
Given:
There is a stream with ingredients, let it be a Stream, you need to make a stream with pizzas (Pizza), which are made from these ingredients according to the recipe (Recipe).
My train of thought.
1) Clear the stream from ingredients that are not in the recipe:
stream.filter(ing -> !recipe.contains(ing))
2) Next, you need to assemble a pizza from these ingredients, the first thing that comes to mind is the map () method, which converts the stream elements, but the problem is that the pizza consists of many ingredients that need to be collected from the original stream, but on he is given only one parameter to enter, how can you solve this problem and collect a stream of pizzas from a stream of ingredients?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elmo Sputterspark, 2019-07-19
@NeoIsNotTheOne

A stream, as its name implies, is a stream. How many floated, so many floated. The only way to collect something from several stream elements is to write a collector.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question