Mapping countries

Report a typo

Given the following list of countries:

List<String> countries = Arrays.asList("Costa Rica", "Hungary", "Saint Kitts and Nevis", "Norway");

Enter all elements of the list numbers separated by spaces (for example: 1 2 3).

List<Integer> numbers = countries.stream()
        .map(country -> country.split("\\s+"))
        .map(country -> country.length)
        .collect(Collectors.toList());
Enter a short text
___

Create a free account to access the full topic