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. 使用Myeclipse 2015 进行 Hdp 4 windows 开发

    在本地环境下进行开发,使用cygwin安装 Hdp那就是一个呵呵岂能概括. 所以啊,还是用Hdp windows进行开发测试吧.这样感觉省心点.具体 Hdp windows的安装参看前面的文章或自行G ...

  2. shell之条件表达式

    conditional expressions are used by the [[ compound command and the test and [ builtin commands. ari ...

  3. Review Board——在线代码审查工具

    代码审查(Code Review)不但可以提高质量,而且还是一个知识共享和指导的极好的手段.不幸的是,准备工作的辛苦和工具支持的缺乏让代码审查很容易被延至“稍后再议”.Review Board的目标便 ...

  4. 设计师必看的10个HTML5动画工具

    如果你想用令人难以置信的动画创建引人注目的网站的话,那么这里为设计师精心挑选了一些必备的HTML5动画工具.HTML5是设计师用来打造时尚网站的最流行的编程语言之一.在过去三年内,这种编程语言的使用人 ...

  5. 程序员书单_java学习基础编程篇

    Java程序设计语言.(美国)阿诺德.清晰版 http://download.csdn.net/detail/shenzhq1980/9076093 JAVA2核心技术第1卷.基础知识7th.part ...

  6. 【jmeter】WebSerivice测试

    WebSerivice测试计划的取样器有两种方式:HTTP请求.SOAP/XML-RPC Request. 1. 测试计划 启动JMeter,点击测试计划节点上,重命名测试计划:WebserviceT ...

  7. Async 、 Await 的异步编程(.NET 4.5 新异步模型) [转自MSDN]

    使用异步编程,可以避免性能瓶颈和增强应用程序的总体响应能力. 但是,编写异步应用程序的以前的技术可能比较复杂,使它们难以编写,调试和维护. Visual Studio 2012 引入了一个简化的方法, ...

  8. LinearLayout属性baselineAligned的作用及baseline

    相信大家对LinearLayout已经相当熟悉,但你们是否了解它的属性baselineAligned呢? Android官方文档是这么描述的:

  9. FullCalendar

    一个非常完美的日期控件:https://fullcalendar.io/

  10. 【并发编程】Executor类的继承结构

    来自为知笔记(Wiz)