1.list转set
Set set = new HashSet(new ArrayList());

2.set转list
List list = new ArrayList(new HashSet());

3.数组转为list
List stooges = Arrays.asList("Larry", "Moe", "Curly");
或者
String[] arr = {"1", "2"};
List list = Arrays.asList(arr);

4.数组转为set
int[] a = { 1, 2, 3 };
Set set = new HashSet(Arrays.asList(a));

5.map的相关操作。
Map map = new HashMap();
map.put("1", "a");
map.put('2', 'b');
map.put('3', 'c');
System.out.println(map);
// 输出所有的值
System.out.println(map.keySet());
// 输出所有的键
System.out.println(map.values());
// 将map的值转化为List
List list = new ArrayList(map.values());
System.out.println(list);
// 将map的值转化为Set
Set set = new HashSet(map.values());
System.out.println(set);

6.list转数组
List list = Arrays.asList("a","b");
String[] arr = (String[])list.toArray(new String[list.size()]);
System.out.println(Arrays.toString(arr));

//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();

/**
* List<Map<Object,Object>> to 二维数组
* @param list
* @param keyLength - Map中的key个数
* @return
*/
public static Object[][] list2array(List<Map<Object,Object>> list,int keyLength){
Object[][] array = new Object[list.size()][keyLength];
for(int i=0;i<list.size();i++){
array[i] = list.get(i).values().toArray();
}
return array;
}

list,set,map,数组之间的相互转换详细解析的更多相关文章

  1. list,set,map,数组间的相互转换

    1.list转set Set set =  new  HashSet( new  ArrayList()); 2.set转list List list =  new  ArrayList( new   ...

  2. c++中string类对象和字符数组之间的相互转换

    string类在c++中是一个模板类,位于名字空间std中,注意这里不是string.h,string.h是C字符串头文件. 将string类型转换为字符数组char arr[10];string s ...

  3. Java中字符串和byte数组之间的相互转换

    1.将字符转换成byte数组 String str = "罗长"; byte[] sb = str.getBytes(); 2.将byte数组转换成字符 byte[] b={(by ...

  4. 【python】列表与数组之间的相互转换

    安装numpy pip3 install numpy 列表转数组 np.array() import numpy as np a = [1, 2, 3] b = np.array(a) 列表转数组 a ...

  5. C#中List〈string〉和string[]数组之间的相互转换

    1,从System.String[]转到List<System.String> System.String[] str={"str","string" ...

  6. List<string>和string[]数组之间的相互转换,需要的朋友可以参考下

    1,从System.String[]转到List<System.String> System.String[] str={"str","string" ...

  7. c#不同数组之间的转换【转载,消化自动删除】

    c#中从string数组转换到int数组 string[] input = { "1", "2", "3", "4", ...

  8. JavaScriptES6中Map与对象、数组,JSON之间的相互转换

    JavaScriptES6中Map与对象.数组,JSON之间的相互转换 https://blog.csdn.net/c__dreamer/article/details/82183130

  9. Json数组操作小记 及 JSON对象和字符串之间的相互转换

    [{"productid":"1","sortindex":"2"},{"productid":&q ...

随机推荐

  1. 在CentOS上安装Python

    首先我们需要在服务器上安装一个比较新的 Python,CentOS 5.8 默认装的 Python 是 2.4.3. [root@nowamagic ~]# python -V Python 我们需要 ...

  2. createdb test时报global/pg_filenode.map不存在

    实际上是存在的,看到说是ipv6占用了5432的端口号,看了一下的确是,将ipv6关闭重启系统即可. 下面是关闭ipv6的方法: 确认IPV6是否开启 在Linux下确认IPv6是否已经被启用,可以从 ...

  3. c# 图片XML序列化与反序列化

    var xmlDoc = new XmlDocument(); xmlDoc.Load(@"C:\Users\*\Desktop\*.xml"); ].ChildNodes[]; ...

  4. httpd-2.2

    http://httpd.apache.org/docs/2.2/logs.html httpd.conf文件 Configuration and logfile names: If the file ...

  5. Cobar使用文档(可用作MySQL大型集群解决方案)

    原文:http://my.oschina.net/ydsakyclguozi/blog/374564 最近好不容易抽空研究了下Cobar,感觉这个产品确实很不错(在文档方面比Amoeba强多了),特此 ...

  6. [mysql] linux 下mysql 5.7.12 安装

    1.下载mysql wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar ...

  7. HTML5新事物

    1 指定编码字符集,极力推荐 <meta charset="utf-8"> 2 指定lang,所有的标签上都有,推荐在<html>上指定. 3 css样式的 ...

  8. 响应式布局设置--@media only screen and

    @media only screen and  only(限定某种设备) screen 是媒体类型里的一种 and 被称为关键字,其他关键字还包括 not(排除某种设备) /* 常用类型 */类型 解 ...

  9. 【linux】输出重定向

    “>”:把正确结果输出到一个文件 [root@andon ~]# ls > 1 [root@andon ~]# cat 1 1 anaconda-ks.cfg install.log in ...

  10. SPOJ #429 Simple Numbers Conversion

    This is simply a human work simulation - exactly reproducing how you do it by hand. Nothing special. ...