java simpleentry_使用Java流生成对象

一张地图包括国家名称作为关键字,城市列表作为值。

List inCities = new ArrayList(Arrays.asList("Delhi", "Mumbai", "Hyderabad", "Banglore", "Chennai"));

List jpCities = new ArrayList(Arrays.asList("Tokyo", "Osaka", "Kyoto"));

List usCities = new ArrayList(Arrays.asList("Dallas", "Chicago", "NewYork"));

List ukCities = new ArrayList(Arrays.asList("London", "Cardiff", "Oxford"));

List frCities = new ArrayList(Arrays.asList("Paris", "Marseille", "Lyon"));

Map> countryWiseCities = new HashMap>();

countryWiseCities.put("India", inCities);

countryWiseCities.put("Japan", jpCities);

countryWiseCities.put("USA", usCities);

countryWiseCities.put("UK", ukCities);

countryWiseCities.put("France", frCities);

List asiaCountries = new ArrayList(Arrays.asList("India", "Japan"));

List northAmericaCountries = new ArrayList(Arrays.asList("USA", "Canada"));

List europeCountries = new ArrayList(Arrays.asList("UK", "France"));

Map> continentWiseCountries = new HashMap>();

continentWiseCountries.put("Asia", asiaCountries);

continentWiseCountries.put("NorthAmerica", northAmericaCountries);

continentWiseCountries.put("Europe", europeCountries);

现有地图。

{"India":["Delhi", "Mumbai", "Hyderabad", "Banglore", "Chennai"], "Japan":["Tokyo", "Osaka", "Kyoto"], "USA":["Dallas", "Chicago", "NewYork"], "Canada":["Ontario", "Toronto", "vancouver"],

"UK":["London", "Cardiff", "Oxford"], "France":["Paris", "Marseille", "Lyon"]}

{"Asia":["India", "Japan"], "NorthAmerica":["USA", "Canada"], "Europe":["UK", "France"]}

我正在寻找一种使用java流在地图下方构建的方法。使用Java流实现以下输出的最简单方法是什么?。

预期产量:

{"ASIA":["Delhi", "Mumbai", "Hyderabad", "Banglore", "Chennai", "Tokyo", "Osaka", "Kyoto"],

"NorthAmerica":["Dallas", "Chicago", "NewYork", "Ontario", "Toronto", "vancouver"],

"Europe":["London", "Cardiff", "Oxford", "Paris", "Marseille", "Lyon"]

这里的关键是大陆名。

下面是我尝试过的代码。

Map>>> collect1 = countryWiseCities.entrySet().stream()

.collect(Collectors.groupingBy(Map.Entry::getKey));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值