Challenge: Selecting Random Products Within a Category
Tâche
Swipe to start coding
Imagine you have a list of products from an online store. Your goal is to group them by category, pick a random product from each group, and display the result.
- Group the list of products by
categoryusinggroupingBy(). - For each category (
productList), get the list of products using thestream()method and select a random product withfindAny(). - Check if the
Optionalcontains a value usingifPresent(). - If
Optionalhas a value, print the information in the following format:"Category: {category} => {product}".
Solution
solution.java
Tout était clair ?
Merci pour vos commentaires !
Section 3. Chapitre 11
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Awesome!
Completion rate improved to 2.33
Challenge: Selecting Random Products Within a Category
Glissez pour afficher le menu
Tâche
Swipe to start coding
Imagine you have a list of products from an online store. Your goal is to group them by category, pick a random product from each group, and display the result.
- Group the list of products by
categoryusinggroupingBy(). - For each category (
productList), get the list of products using thestream()method and select a random product withfindAny(). - Check if the
Optionalcontains a value usingifPresent(). - If
Optionalhas a value, print the information in the following format:"Category: {category} => {product}".
Solution
solution.java
Tout était clair ?
Merci pour vos commentaires !
Section 3. Chapitre 11
single