Challenge: Selecting Random Products Within a Category
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
category
usinggroupingBy()
. - For each category (
productList
), get the list of products using thestream()
method and select a random product withfindAny()
. - Check if the
Optional
contains a value usingifPresent()
. - If
Optional
has a value, print the information in the following format:"Category: {category} => {product}"
.
Ratkaisu
solution.java
Kiitos palautteestasi!
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Awesome!
Completion rate improved to 2.33Awesome!
Completion rate improved to 2.33
Challenge: Selecting Random Products Within a Category
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
category
usinggroupingBy()
. - For each category (
productList
), get the list of products using thestream()
method and select a random product withfindAny()
. - Check if the
Optional
contains a value usingifPresent()
. - If
Optional
has a value, print the information in the following format:"Category: {category} => {product}"
.
Ratkaisu
solution.java
Kiitos palautteestasi!
single
Awesome!
Completion rate improved to 2.33
Challenge: Selecting Random Products Within a Category
Pyyhkäise näyttääksesi valikon
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
category
usinggroupingBy()
. - For each category (
productList
), get the list of products using thestream()
method and select a random product withfindAny()
. - Check if the
Optional
contains a value usingifPresent()
. - If
Optional
has a value, print the information in the following format:"Category: {category} => {product}"
.
Ratkaisu
solution.java
Kiitos palautteestasi!