[英]Convert double list objects in object list to string
I am having a list of data objects. 我有一个数据对象列表。 Each data object has a
resultList
of double elements which can also be null. 每个数据对象都有一个double元素的
resultList
,也可以为null。
I want pull out this resultList
of the data object and store them seperately in a string list: 我想拉出数据对象的
resultList
并将它们分别存储在字符串列表中:
List<List<String>> ar_List = new ArrayList<List<String>>();
for (int i = 0; i < dataList.size(); i++) {
for (int j = 0; j < dataList.get(i).getResultList().size(); j++) {
ar_List.add(dataList.get(i).getResultList().get(j).toString());
}
}
However I still get an error at ar_List.add(dataList.get(i).getResultList().get(j).toString());
但是我仍然在
ar_List.add(dataList.get(i).getResultList().get(j).toString());
Any recommendations how to write the List Objects into ar_List
? 有关如何将列表对象写入
ar_List
任何建议?
I appreciate your answers! 我感谢你的回答!
replace 更换
ar_List.add(dataList.get(i).getResultList().get(j).toString());
with 同
ar_List.get(i).add(dataList.get(i).getResultList().get(j).toString());
Check if the data is null because calling toString()
on a null object causes a NPE. 检查数据是否为null,因为在null对象上调用
toString()
会导致NPE。 And you need to get the List<String>
and not List<List<String>>
您需要获取
List<String>
而不是List<List<String>>
if(dataList.get(i).getResultList().get(j) != null) {
ar_List.get(i).add(dataList.get(i).getResultList().get(j).toString());
}
In order to check for null lists either filter the parent list for null objects or change the for condition. 为了检查空列表,请过滤空列表的父列表或更改for条件。
for(in j = 0; j < dataList.get(i).getResultList().size(); dataList.get(i).getResultList().get(j)==null?j+=2:j++)
This jumps over the next row if the next row is null. 如果下一行为空,则跳过下一行。 But the better would be to clean the list.
但更好的是清理清单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.