Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Selecting the Best Cars on the Production Line | Intermediate Operations in Stream API
Stream API
course content

Conteúdo do Curso

Stream API

Stream API

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

book
Challenge: Selecting the Best Cars on the Production Line

Tarefa

Swipe to start coding

At the factory, you need to process a list of cars, filter them based on mileage, sort them according to specific criteria, and display the results.

Each car is represented by the Car class, which contains an id as a unique identifier, a model specifying the car’s name, a year indicating when it was manufactured, and a mileage field representing the total distance it has traveled.

  1. Filter the cars, keeping only those with a mileage of 30,000 miles or less using the filter() method.
  2. Sort the cars by year in ascending order using comparingInt() method.
  3. Once the cars are sorted by year, reverse the order to have the newest cars first using reversed() method.
  4. If two cars have the same year, sort them by mileage in ascending order using thenComparing() method.
  5. Convert each car object to a string representation, using the toString() method.
  6. Print the final list to the console, using a method reference to println().

Solução

java

solution

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 6
toggle bottom row

book
Challenge: Selecting the Best Cars on the Production Line

Tarefa

Swipe to start coding

At the factory, you need to process a list of cars, filter them based on mileage, sort them according to specific criteria, and display the results.

Each car is represented by the Car class, which contains an id as a unique identifier, a model specifying the car’s name, a year indicating when it was manufactured, and a mileage field representing the total distance it has traveled.

  1. Filter the cars, keeping only those with a mileage of 30,000 miles or less using the filter() method.
  2. Sort the cars by year in ascending order using comparingInt() method.
  3. Once the cars are sorted by year, reverse the order to have the newest cars first using reversed() method.
  4. If two cars have the same year, sort them by mileage in ascending order using thenComparing() method.
  5. Convert each car object to a string representation, using the toString() method.
  6. Print the final list to the console, using a method reference to println().

Solução

java

solution

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 6
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt