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, 1 month agoInnovation
Highly Voted 5 years, 1 month agogriglad
3 years ago6c84cb9
Most Recent 7 months, 1 week agoshivkumarx
1 year agoasdfjhfgjuaDCV
1 year agosteefaand
1 year, 1 month agoEden0516
1 year, 5 months agoduydn
1 year, 5 months agoGaelBernard
1 year, 7 months agor1muka5
2 years agomevlt
3 years agoWilsonKKerll
3 years agobnagaraja9099
3 years, 10 months agoSvetleto13
3 years, 10 months agoSvetleto13
3 years, 10 months agogriglad
3 years agoHuim
3 years, 10 months agoSvetleto13
3 years, 9 months agoAstelitik
4 years, 6 months agoAstelitik
4 years, 6 months agorameasy
4 years, 7 months agoChoucou
5 years, 5 months ago