7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Javaの配列・リスト・ストリーム相互変換一覧表

Posted at

インスタンスメソッドで直接変換できたり、クラスメソッドで用意されていたり、もっと複雑なことが必要だったり、ややこしかったので纏めておく。

from \ to T[] List<T> Stream<T>
T[] array Arrays.copyOf(array, array.length) Arrays.asList(array) (固定長・配列と連動) Arrays.stream(array)

Stream.of(array)
List<T> list list.toArray(new T[0]) new ArrayList<>(list)

Collections.unmodifiableList(list) (変更不可)
list.stream()

list.parallelStream() (並列)
Stream<T> stream stream.toArray(T[]::new) stream.collect(Collectors.toList()) ※コピー不可、データソースから組み直すこと

ドキュメント:

その他:

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?