Given the definition of the Country class:
public class country {
public enum Continent {ASIA, EUROPE}
String name;
Continent region;
public Country (String na, Continent reg) {
name = na, region = reg;
}
public String getName () {return name;}
public Continent getRegion () {return region;}
}
and the code fragment:
List<Country> couList = Arrays.asList (
new Country ("Japan", Country.Continent.ASIA),
new Country ("Italy", Country.Continent.EUROPE),
new Country ("Germany", Country.Continent.EUROPE));
Map<Country.Continent, List<String>> regionNames = couList.stream ()
.collect(Collectors.groupingBy (Country ::getRegion,
Collectors.mapping(Country::getName, Collectors.toList()))));
System.out.println(regionNames);
M_Jawad
Highly Voted 5 years, 6 months agoInnovation
Highly Voted 5 years, 6 months agogriglad
3 years, 5 months ago6c84cb9
Most Recent 11 months, 2 weeks agoshivkumarx
1 year, 4 months agoasdfjhfgjuaDCV
1 year, 4 months agosteefaand
1 year, 5 months agoEden0516
1 year, 9 months agoduydn
1 year, 9 months agoGaelBernard
1 year, 11 months agor1muka5
2 years, 4 months agomevlt
3 years, 4 months agoWilsonKKerll
3 years, 4 months agobnagaraja9099
4 years, 2 months agoSvetleto13
4 years, 2 months agoSvetleto13
4 years, 2 months agogriglad
3 years, 5 months agoHuim
4 years, 2 months agoSvetleto13
4 years, 1 month agoAstelitik
4 years, 10 months agoAstelitik
4 years, 10 months agorameasy
4 years, 11 months agoChoucou
5 years, 10 months ago