1.java中怎样只把Map<String, Map<String, String>>生成一个新的Local对象的新的list
Map<String, Map<String, String>> localeMsgMap = allLocaleMessage
// stream流
.stream()
// 分组
.collect(Collectors.groupingBy(
// 根据国家地区分组
I18Message::getLocale,
// 收集为Map,key为code,value为信息
Collectors.toMap(
I18Message::getKey
, I18Message::getItem
)
));
List<Locale> localeList = localeMsgMap.keySet().stream().map( Locale::new).collect(Collectors.toList());
2.java中怎样只把Map<String, Map<String, String>>的key值中的-修改成_并生成一个新的Local对象的新的list
import com.google.common.collect.ImmutableMap;
Map<String, Map<String, String>> localeMsgMap = allLocaleMessage
// stream流
.stream()
// 分组
.collect(Collectors.groupingBy(
// 根据国家地区分组
I18Message::getLocale,
// 收集为Map,key为code,value为信息
Collectors.toMap(
I18Message::getKey
, I18Message::getItem
)
));
List<Locale> localeList = localeMsgMap.keySet().stream().map( Locale::new).collect(Collectors.toList());
List<Locale> localeList = localeMsgMap.entrySet().stream()
.map(entry -> {
//这里用ImmutableMap.copyOf进行深拷贝
Map<String, String> newValue = ImmutableMap.copyOf(entry.getValue());
return new Locale(entry.getKey().replace("-", "_"));
})
.collect(Collectors.toList());