map相关操作:map遍历,map转换为list

public  static void retunKeyAndValue(Map<String,Object> map){
        System.out.println("通过Map.entrySet遍历key和value");
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            System.out.println("key = " + entry.getKey() + " and value = " + entry.getValue());
        }
    }


    /**
     * map 转换成list
     */

    public static List  returnList(Map map) {
        List list = new ArrayList();
        Iterator iter = map.entrySet().iterator();  //获得map的Iterator
        while(iter.hasNext()) {
            Entry entry = (Entry)iter.next();
            list.add(entry.getValue());
        }
        return list;
    }

  

原文地址:https://www.cnblogs.com/codekey/p/4643130.html