Write a class City (name, country, population in millions) and CityGroups, which reads name country millions lines and uses Collectors to print:
- country → list of city names (
groupingBywithTreeMap::newandmapping), - country → number of cities (
counting), - country → total population (
summingDouble), one line per country, - the megacities (≥ 10 million) and the others (
partitioningBy), - the country with the largest total (stream over
entrySet()withmax).
For the input
Shanghai China 24.9
Niamey Niger 1.4
Beijing China 21.5
Lagos Nigeria 15.4
Zinder Niger 0.5
Abuja Nigeria 3.8
the program prints
Cities: {China=[Shanghai, Beijing], Niger=[Niamey, Zinder], Nigeria=[Lagos, Abuja]}
Counts: {China=2, Niger=2, Nigeria=2}
China: 46.4 million
Niger: 1.9 million
Nigeria: 19.2 million
Megacities: [Shanghai, Beijing, Lagos]
Others: [Niamey, Zinder, Abuja]
Most urban population: China