![](/img/trans.png)
[英]How can i convert Map of Strings and Object to a Map of Strings and List
[英]How to convert List of Object into List of Strings
我正在嘗試將對象列表轉換為字符串列表
我的自定義對象列表是這樣的
convertData {rawMaterialId:“ 3411”,batchNumber:“ 166,465,963,962,785”,位置:“ hhh,ooo,hhh,uio,pop”,數量:“ 900,302,560,650,989”}
我正在嘗試將此JSON對象轉換為字符串列表
看起來應該像這樣
列表[“ 3411”,“ 166”,“ 465”,“ 963”,“ hhh”,“ ooo”,“ pop”,“ 900”,“ 302”,“ 560”]
我嘗試了以下代碼
String[] array = new String[convertedData.size()];
int index = 0;
for (Object value : convertedData) {
array[index] = (String) value;
index++;
}
歡迎提出任何建議和指正。謝謝。
您應該拆分轉換后的數據。
List<String> list = new ArrayList<>();
for (Object value : convertedData) {
if (value instanceof String) {
String str = (String) value;
list.addAll(Arrays.asList(str.split(",")));
}
}
String[] array = list.toArray(new String[list.size()]);
List<String> list = new ArrayList<>();
for (Object value : convertedData) {
String[] wordList = ((String) value).split(",");
for (String val : wordList) {
list.add(val);
}
}
String[] stringArray = list.toArray(new String[list.size()]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.