list,set,map,数组之间的相互转化

//list 转 set
Set set = new HashSet(new ArrayList());	

 

 

//set 转 list
List list = new ArrayList(new HashSet());

 

 

//数组 转为 list
List list = Arrays.asList("linana","moe","jim");

 

 

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

 

 

//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());
List list = new ArrayList(map.values());//将map的值转化为list
System.out.println(list);
Set set = new HashSet(map.values());//将map的值转化为set
System.out.println(set);
 

 

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

你可能感兴趣的:(C++,c,C#)