2019-8-26 LinkedHashMap 转 List [java.util.LinkedHashMap cannot be cast to com.zq.dataservice.bean.Index]
java.util.LinkedHashMap cannot be cast to com.zq.dataservice.bean.Index
上述错误是在做一个趋势投资demo时遇到的.
说的是链式HashMap不能转换为单个对象进行foreach
其解决:
private List<IndexData> map2IndexData(List<Map> temp) { List<IndexData> indexDatas = new ArrayList<>(); for (Map map : temp) { String date = map.get("date").toString(); float closePoint = Convert.toFloat(map.get("closePoint")); IndexData indexData = new IndexData(); indexData.setDate(date); indexData.setClosePoint(closePoint); indexDatas.add(indexData); } return indexDatas; }
private List<Index> map2Index(List<Map> temp) { List<Index> indexes = new ArrayList<>(); for (Map map : temp) { String code = map.get("code").toString(); String name = map.get("name").toString(); Index index= new Index(); index.setCode(code); index.setName(name); indexes.add(index); } return indexes; }
本文来自博客园,作者:ukyo--君君小时候,转载请注明原文链接:https://www.cnblogs.com/ukzq/p/11411389.html