list,set,map,數(shù)組之間的相互轉(zhuǎn)換詳細(xì)解析
1.list轉(zhuǎn)set
Set set = new HashSet(new ArrayList());
2.set轉(zhuǎn)list
List list = new ArrayList(new HashSet());
3.數(shù)組轉(zhuǎn)為list
List stooges = Arrays.asList("Larry", "Moe", "Curly");
或者
String[] arr = {"1", "2"};
List list = Arrays.asList(arr);
4.數(shù)組轉(zhuǎn)為set
int[] a = { 1, 2, 3 };
Set set = new HashSet(Arrays.asList(a));
5.map的相關(guān)操作。
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的值轉(zhuǎn)化為List
List list = new ArrayList(map.values());
System.out.println(list);
// 將map的值轉(zhuǎn)化為Set
Set set = new HashSet(map.values());
System.out.println(set);
6.list轉(zhuǎn)數(shù)組
List list = Arrays.asList("a","b");
String[] arr = (String[])list.toArray(new String[list.size()]);
System.out.println(Arrays.toString(arr));
相關(guān)文章
詳解Java實(shí)現(xiàn)多種方式的http數(shù)據(jù)抓取
本篇文章主要介紹了Java實(shí)現(xiàn)多種方式的http數(shù)據(jù)抓取,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧。2016-12-12JAVA中的靜態(tài)代理、動態(tài)代理以及CGLIB動態(tài)代理總結(jié)
本篇文章主要介紹了JAVA中的靜態(tài)代理、動態(tài)代理以及CGLIB動態(tài)代理總結(jié),具有一定的參考價值,有興趣的可以了解一下2017-08-08