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)化為L(zhǎng)ist
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));
新聞熱點(diǎn)
疑難解答
圖片精選