List>集合中获取某个key并转换为List集合


package com.codyy.sso.controller.yuanqu;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
public class Test {
    public static void main(String[] args) {
         List<Map<String, Object>> listMaps = new ArrayList<Map<String, Object>>();
            
            Map<String, Object> map1 = new HashMap<String, Object>();
            map1.put("ID", "123");
            map1.put("Name", "管理员2");
            map1.put("year", "11010");
            listMaps.add(map1);
            System.out.println(listMaps);
            System.out.println("___________________________");
            
            Map<String, Object> map2 = new HashMap<String, Object>();
            map2.put("ID", "456");
            map2.put("Name", "测试员");
            map2.put("Year", "321010");
            listMaps.add(map2);
            System.out.println(listMaps);
            
            String role = null ;
            StringBuffer roles = new StringBuffer();
            for(int i = 0;i < listMaps.size();i++){
                // 取出ID的值,拼接到roles中去
                role = (String)listMaps.get(i).get("ID");
                System.out.println("ID的值为:" + role);
                roles.append(role + ",");
            }

             String[] str =roles.toString().split(",");
             List<Integer> Lids = new ArrayList<Integer>();
            for (int i = 0; i < str.length; i++) {
              Lids.add(new Integer(str[i]));
             }

            System.out.println(Lids);
            
            
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM