java集合业务问题:取出List⾥⾯Map的key:value值1.取出Map其中⼀个属性的值
Map map =new HashMap();
map.put("key1","value1");
map.put("key2","value2");
List> list =new ArrayList>();
list.add(map);
for(int i =0;i < list.size();i++)
{
Map<String,Object> map = (i);
String authorStr = ("key1").toString();
System.out.println("author"+" : "+ authorStr);
}
//实例应⽤
List<Map<String, Object>> grouppList = fpService.findFp();
for(int i =0;i < grouppList.size();i++){
Map<String, Object> map = (i);
String str = ("sky").toString();
System.out.println("sky的值"+" : "+ str);
}
2.取出所有的key:value
//第⼀种:
Map map =new HashMap();
map.put("key1","value1");
map.put("key2","value2");
<List> list =new ArrayList>();
list.add(map);
for(Map m : list)
{
for(String k : m.keySet())
{
System.out.println(k +" : "+ m.get(k));
}
}
/
/第⼆种:
Map map =new HashMap();
map.put("key1","value1");
map.put("key2","value2");
<List> list =new ArrayList>();
list.add(map);
for(Map map:list)
{
for(Map.Entry e:map)
{
}
}
//第三种:
Map map =new HashMap();
map.put("key1","value1");
map.put("key2","value2");
<List> list =new ArrayList>();
list.add(map);
for(int i=0;i<list.size();i++)
{
Map  map1=((i);
Iterator iterator = map1.keySet().iterator();
while(iterator.hasNext())
{
String key =(String) ();
Object object = (key);java valueof
System.out.println(object);
}
}
3.业务上需要循环出来总数
List<Map<String,Object>> toTalList = equitotalDAO.selectToTal();
Integer sl =0;
for(int k =0;k<toTalList.size();k++){
Map<String,Object> map = (k);
sl += Integer.("equiShoujiu").toString());
//此处Object转 int 解决思路:先Object转String然后String转 int
}
原⽂链接:blog.csdn/weixin_42842069/article/details/95223879

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。