Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Implement a Custom Predicate | Getting Started with Lambda Expressions
Quizzes & Challenges
Quizzes
Challenges
/
Lambda Expressions in Java

bookChallenge: Implement a Custom Predicate

Imagine you are building a product search feature for an online store. You want to help users quickly find products by filtering a list of product names. For instance, you might want to find all products that start with the letter "S". Instead of hardcoding the filtering logic, you decide to create a custom predicate interface that allows you to pass any filtering condition as a lambda expression. This makes your code flexible and reusable for different search criteria.

Завдання

Swipe to start coding

Implement a method to filter a list of strings using a custom predicate. The method should apply the predicate to each string and return a new list containing only the strings that match the predicate.

  • Iterate through each element in the items list.
  • For each element, check if it satisfies the predicate.
  • If the element satisfies the predicate, add it to a new list.
  • Return the new list containing all matching elements.

Рішення

Все було зрозуміло?

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

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

Секція 1. Розділ 6
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

close

bookChallenge: Implement a Custom Predicate

Свайпніть щоб показати меню

Imagine you are building a product search feature for an online store. You want to help users quickly find products by filtering a list of product names. For instance, you might want to find all products that start with the letter "S". Instead of hardcoding the filtering logic, you decide to create a custom predicate interface that allows you to pass any filtering condition as a lambda expression. This makes your code flexible and reusable for different search criteria.

Завдання

Swipe to start coding

Implement a method to filter a list of strings using a custom predicate. The method should apply the predicate to each string and return a new list containing only the strings that match the predicate.

  • Iterate through each element in the items list.
  • For each element, check if it satisfies the predicate.
  • If the element satisfies the predicate, add it to a new list.
  • Return the new list containing all matching elements.

Рішення

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

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

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

Секція 1. Розділ 6
single

single

some-alt