List>取值

时间:2022-02-17 19:11:51
List<Map<String, Object>> postlist    //一个list里面装着多个map,如下
[
    {A=0100, B=4}, 
    {A=0200, B=3}, 
    {A=0300, B=2}
]
for(int i = 0 ; i < postlist.size() ; i ++){
    System.out.println(postlist.get(i).get("A"));    //循环打印list里面map键为"A"的值,类型为Object
    System.out.println(String.valueOf(postlist.get(i).get("placeTo")));    // 打印"A"的值,Object转成String
    System.out.println(Integer.parseInt(String.valueOf(postlist.get(i).get("placeTo"))))    //打印"A"的值,Object转成String,String转成Integer
}

如果list里面装的是对象
for(int i = 0 ; i < list.size() ; i ++){
    list.get(i).getA();
}