Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Selecting Random Products Within a Category | Terminal Operations in the Stream API
Stream API
course content

Зміст курсу

Stream API

Stream API

1. Fundamentals and Functional Capabilities of Stream API
4. Practical Applications of Stream API

book
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.

  1. Group the list of products by category using groupingBy().
  2. For each category (productList), get the list of products using the stream() method and select a random product with findAny().
  3. Check if the Optional contains a value using ifPresent().
  4. If Optional has a value, print the information in the following format: "Category: {category} => {product}".

Рішення

java

solution

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 11
toggle bottom row

book
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.

  1. Group the list of products by category using groupingBy().
  2. For each category (productList), get the list of products using the stream() method and select a random product with findAny().
  3. Check if the Optional contains a value using ifPresent().
  4. If Optional has a value, print the information in the following format: "Category: {category} => {product}".

Рішення

java

solution

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 11
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt