![](/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.