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

Kursinhalt

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

Aufgabe

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().

Lösung

java

solution

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 6
toggle bottom row

book
Challenge: Selecting the Best Cars on the Production Line

Aufgabe

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().

Lösung

java

solution

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 2. Kapitel 6
Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
We're sorry to hear that something went wrong. What happened?
some-alt