配列からリストへの変換方法

変換方法はた種類ある

方法 可変型 or 不変型 参照型配列 プリミティブ型配列 set()による変更で配列に影響
1. Collections.addAll() 可変型 〇(boxed()が必要) ×
2. Arrays.asList() 可変型(※サイズ変更不可) 〇(boxed()が必要) 〇(参照型のみ)
3. List.of() 不変型 〇(boxed()が必要) ×
4. Arrays.stream().collect(Collectors.toList()) 可変型 〇(boxed()が必要) ×
5. Arrays.stream().toList() 不変型 〇(boxed()が必要) ×
6. Arrays.stream(array).boxed().toList() 不変型 〇(プリミティブ不可) 〇(boxed()が必要) ×
7. Arrays.stream(array).boxed().collect(Collectors.toList()) 可変型 〇(プリミティブ不可) 〇(boxed()が必要) ×

詳細(cgより)


投稿日

カテゴリー:

, , ,

投稿者:

タグ: