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轉ArrayString[] dest = list.toArray(new String[0]);//new String[0]是指定返回陣列的型別System.out.println("dest: " + Arrays.toString(dest));
List轉SetSet<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]);
最新評論