Java代码如下:

package Test01;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry; public class Test05 { // map转换成list
@SuppressWarnings({ "unchecked", "rawtypes" })
public static List mapTransitionList(Map map) {
List list = new ArrayList();
Iterator iter = map.entrySet().iterator(); // 获得map的Iterator
while (iter.hasNext()) {
Entry entry = (Entry) iter.next();
list.add(entry.getKey());
list.add(entry.getValue());
}
return list;
} @SuppressWarnings("unchecked")
public static void main(String[] args) {
@SuppressWarnings("rawtypes")
Map map = new HashMap();
map.put("aaa", 11);
map.put("bbb", "22ss");
map.put("ccc", "汉字");
@SuppressWarnings("rawtypes")
List list = mapTransitionList(map);
for (int i = 0; i < list.size(); i++) {
System.out.print(list.get(i) + " ");
}
}
}

代码运行后效果如下:

map转换成list的更多相关文章

  1. 简单的map转换成Bean的工具

    简单的map转换成Bean的工具 package com.sd.microMsg.util; import java.lang.reflect.Field; import java.lang.refl ...

  2. Map 转换成byte[] 数组

    把Map转换成byte数组,使用 ByteArrayOutputStream和ObjectOutputStream Map<String,String> map = new HashMap ...

  3. 泛型(二)封装工具类CommonUtils-把一个Map转换成指定类型的javabean对象

    1.commons-beanutils的使用 commons-beanutils-1.9.3.jar 依赖 commons-logging-1.2.jar 代码1: String className ...

  4. java list map转换成二维数组

    /** * *@Title: ListToArray *@Description: list列表转换成二维数组 *@Author: Administrator *@Since: 2018年1月7日下午 ...

  5. 使用fastjson将list、map转换成json,出现$ref

    这是转换时出现的问题情况( map >> json ) 引用是通过"$ref"来表示的 引用 描述 "$ref":".." 上一 ...

  6. js将map转换成数组

    /** * map转数组. * * @param {Map}map * map对象 * @return 数组 */ Share.map2Ary = function(map) { var list = ...

  7. map转换成JSON的3种方法

    http://www.json.cn/JSON格式校验 1 json-lib <dependency> <groupId>net.sf.json-lib</groupId ...

  8. map转换成com.google.gson.JsonObject

    String json =new Gson().toJson(map); JsonObject jsonObject =new JsonParser().parse(json).getAsJsonOb ...

  9. java中将数组、对象、Map、List转换成JSON数据

    如果要将数组.对象.Map.List转换成JSON数据,那我们需要一些jar包: json-lib-2.4-jdk15.jar ezmorph-1.0.6.jar commons-logging.ja ...

随机推荐

  1. uploadifive源码学习

    一.简介 Uploadify是一个基于JQuery的多文件上传JS组件,高度定制,两个版本可供选择.flash版本在最新的Safari等不再支持flash的浏览器或者一些手机浏览器中就无法正常的加载使 ...

  2. android 联网

    <?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="htt ...

  3. HDU 2544 最短路(dijkstra+邻接矩阵)

    ( ̄▽ ̄)" #include<iostream> #include<cstdio> using namespace std; const int INF=10e7; ...

  4. why TCP guarentee delivery?

    Simple idea: just use a TIMEOUT, if no answer after a certain seconds, just re-deliver!

  5. Shell 流程控制-if for case while until break continue

    Shell 流程控制 和Java.PHP等语言不一样,sh的流程控制不可为空,如(以下为PHP流程控制写法): <?php if (isset($_GET["q"])) { ...

  6. linux 配置tomcat服务器

    1. 找到tomcat安装包    find / -name apache-tomcat* 2. 解压包 tar zxvf apache-tomcat-7.0.67.tar.gz rpm -ivh j ...

  7. python--windows下安装BeautifulSoup

    python有很多内置的模块可以不安装使用,用起来非常方便,但是也有一些挺有用的非内置的模块不能直接使用,需要话费点力气手动安装. 进入python安装目录下的Scripts目录,查看是否有pip工具 ...

  8. Windows安装Composer出现【Composer Security Warning】警告

    提示信息: The openssl extension is missing from the PHP version you specified.This means that secure HTT ...

  9. 作为Web开发人员,我为什么喜欢Google Chrome浏览器

    来源: http://www.cnblogs.com/QLeelulu/archive/2011/08/28/2156402.html 在Google Chrome浏览器出来之前,我一直使用FireF ...

  10. Photoshop 钢笔 双窗口显示

    钢笔:两点成一线  两点:Photoshop 叫锚点 中间线叫做路径 路径变选区 Crtl+Enter 窗口 >>>排列>>> 双联垂直 两个文件同时移动: shi ...