![](/img/trans.png)
[英]How can I make a generic DynamoDBTypeConverter to convert a List of enums into a list of strings ? [DynamoDB]
[英]How to convert list of enums into array of strings?
我有一系列枚举,如下所示:
enum CountryEnum {
MADAGASCAR,
LESOTHO,
BAHAMAS,
TURKEY,
UAE
}
List<CountryEnum> countryList = new ArrayList<>();
countryList.add(CountryEnum.MADAGASCAR);
countryList.add(CountryEnum.BAHAMAS);
如何将我的countryList
转换为String[]
?
我以这种方式尝试 eq :
String[] countries = countryList.toArray(String::new);
但它返回给我ArrayStoreException
。
谢谢你的帮助!
谢谢你的帮助!
它应该这样工作:
String[] strings = countryList.stream()
.map(Enum::toString)
.toArray(String[]::new);
尝试这个:
CountryEnum[] arr = countryList.stream().toArray(CountryEnum[] ::new);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.