首頁>技術>

Array轉List

String[] s = new String[]{"A", "B", "C", "D","E"};List<String> list = Arrays.asList(s);

值得注意的是上邊轉換過來的List並不是java.util.ArrayList,而是java.util.Arrays#ArrayList,這個使用的時候要注意下。

List轉Array
String[] dest = list.toArray(new String[0]);//new String[0]是指定返回陣列的型別System.out.println("dest: " + Arrays.toString(dest));
List轉Set
Set<String> set = new HashSet<>(list);
Set轉List
List<String> list_1 = new ArrayList<>(set);
Array轉Set
s = new String[]{"A", "B", "C", "D","E"};set = new HashSet<>(Arrays.asList(s));
Set轉Array
dest = set.toArray(new String[0]);

9
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • CDN 2021 完全攻擊指南 (三)