Convert and collect unique cities
A travel agency stores city names in lowercase. Before displaying them in brochures, all city names need to be converted to uppercase and stored in a Set to ensure uniqueness.
All the necessary util and stream classes have been imported from you.
Cet exercice fait partie du cours
Input/Output and Streams in Java
Instructions
- Convert each city name to an uppercase letter using
.map(). - Collect the result using
.collect(). - Collect the result in a
Setusing a predefined collect strategy.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
public class CityProcessor {
public static void main(String[] args) {
List cities = List.of("paris", "london", "new york", "paris");
Set uniqueUppercaseCities = cities.stream()
// Convert each city name to uppercase
.____(city -> city.toUpperCase())
// Collect the result and store in a Set
.____(____);
System.out.println(uniqueUppercaseCities);
}
}