三者之间转换关系,一张图清晰呈现。

上代码:

其中的maputils是apache的collection包。

package util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import org.apache.commons.collections.MapUtils; public class Convert {
public static void main(String[] args) {
//1.数组转换为list,map
String[] arr = {"123","456","789","123"};
List<String> list = Arrays.asList(arr);
//数组转换为map,一维数组时,奇数为key,偶数为value,奇数个元素,最后一个舍掉
//.二维数组当做两个一维数组
Map map = MapUtils.putAll(new HashMap(), arr); String[][] ss = {{"a","b","e"},{"c","d","f"}};
MapUtils.debugPrint(System.out,arr,map);
MapUtils.putAll(map, arr);
MapUtils.debugPrint(System.out,arr,map);
MapUtils.putAll(map, ss);
MapUtils.verbosePrint(System.out,arr,MapUtils.invertMap(map)); //list 转换为arr
List<String> ls = new ArrayList<String>();
ls.add("wch");
ls.add("name");
String[] as = (String[]) ls.toArray(); }
}

java中 数组 list map之间的互转的更多相关文章

  1. java中数组、集合、字符串之间的转换,以及用加强for循环遍历

    java中数组.集合.字符串之间的转换,以及用加强for循环遍历: @Test public void testDemo5() { ArrayList<String> list = new ...

  2. java中数组以及集合

    java中数组: 数组在Java里是一种特殊类型,有别于普通的“类的实例”的对象.但实际数组也是一种对象类型,int[]a = new int[5]  a是在java栈中分配的引用变量,类型是int[ ...

  3. java中Integer 和String 之间的转换

    java中Integer 和String 之间的转换 将数组转换成字符串:char[] array = {'a','b','c','d','e'};String str = new String(ar ...

  4. Java中字节与对象之间的转换

    近期公司里面用到了消息队列,而正如我们知道的是消息队列之间的是通过二进制形式的.以下就分享一下java中字节与对象之间的转换. 主要是用到了ByteArrayOutputStream和ObjectOu ...

  5. java中List、Map、Set、Stack、Queue、Collections等的使用

    java中List.Map.Set.Stack.Queue.Collections等的使用 List 创建方法: List<String> list=new ArrayList<&g ...

  6. Java中的映射Map - 入门篇

    前言 大家好啊,我是汤圆,今天给大家带来的是<Java中的映射Map - 入门篇>,希望对大家有帮助,谢谢 简介 前面介绍了集合List,这里开始简单介绍下映射Map,相关类如下图所示 正 ...

  7. java中数组的相关知识

      1. 2.数组的命名方法 1)int[]ages=new int[5]; 2) int[]ages; ages=new int[5]; 3)int[]ags={1,2,3,4,5}; 4)int[ ...

  8. Java中如何遍历Map对象的4种方法

    在java中遍历Map有不少的方法.我们看一下最常用的方法及其优缺点. 既然java中的所有map都实现了Map接口,以下方法适用于任何map实现(HashMap, TreeMap, LinkedHa ...

  9. Java中数组的特性

    转载:http://blog.csdn.net/zhangjg_blog/article/details/16116613 数组是基本上所有语言都会有的一种数据类型,它表示一组相同类型的数据的集合,具 ...

随机推荐

  1. @Autowired中无法注入RestTemplate的问题

    1.在启动类中添加 @Beanpublic RestTemplate restTemplate(){ return new RestTemplate();} 即可解决无法注入RestTemplate的 ...

  2. uboot arp地址解析

    common/cmd_cache.c int do_getmac(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) {     //usend d ...

  3. leetCode(49):Count Primes

    Description: Count the number of prime numbers less than a non-negative number, n. 推断一个数是否是质数主要有下面几种 ...

  4. Java程序执行超时——Future接口介绍

    在Java中,如果需要设定代码执行的最长时间,即超时,可以用Java线程池ExecutorService类配合Future接口来实现. Future接口是Java标准API的一部分,在java.uti ...

  5. USACO zerosum DFS 1A

    USER: Kevin Samuel [kevin_s1] TASK: zerosum LANG: C++ Compiling... Compile: OK Executing... Test 1: ...

  6. Objective-C NSFileManager 文件管理总结

    createFileAtPath //创建文件 NSFileManager *fm = [NSFileManager defaultManager]; NSString *strpath = [NSS ...

  7. BNUOJ 13098 约瑟夫环问题

    C. Josephus Problem 题目链接:http://www.bnuoj.com/v3/contest_show.php?cid=7095#problem/C 题目描述   The hist ...

  8. shell 切割文件

    [root@hadoop2 xiaole_chk_url]# cat looh.index.splitfile.sh loop_c=0loop_step=10001loop_tag=0str_head ...

  9. 如何利用UDP协议封装一个数据包

    在如何封装一个数据包上,是一个非常细致的问题,而利用UDP协议来封装的话,是比较简单,让我们一步步来分析典型的TCP/IP协议.一般来说一个典型的一个数据包,包括以太网MAC头+网络层IP数据头+传输 ...

  10. ASP.NET 4 and Visual Studio 2010

    https://msdn.microsoft.com/en-us/library/ee532866.aspx The topics in this section provide informatio ...