I have troubles using java streams. I have two classes: Pizza class
public class Pizza {
private final String name;
private final List<Ingredient> ingredients;
// ...
}
and Ingredient class with those :
private final String preetyName;
private final int price;
private final boolean meat;
private final boolean spicy;
I need to use streams but I'm pretty new to this.
First I need to make formatted menu:
I have List<Pizza> and after using streams it should return something like this
pizza_name: ingredient1_preetyname, ingredient2_preetyname...\npizza2_name...
as one string. I have something like this but It just a string of all ingredients. I dont know how to add pizza name and \n after ingredients
String lista=pizzas.stream()
.flatMap(p -> p.getIngredients().stream())
.map(i ->i.getPreetyName())
.collect(Collectors.joining(", "));
2.Second thing is I need to return the cheapest spicy(at least one ingredient is spicy) pizza. I know I have to fiter pizzas for spicy ingredients and I know i have to sum ingredients prices but i have honestly no idea how to do that.
If someone could help my in any possible way, I will be thankful.