LoginSignup
3
5

More than 5 years have passed since last update.

【Java】List型・Array型の変換

Last updated at Posted at 2018-11-10

List型をArray型に変換

Foo[] array = list.toArray(new Foo[list.size()]);

もしくは

Foo[] array = new Foo[list.size()];
list.toArray(array);

Array型をList型に変換

String[] stringArray = {"aaa", "bbb", "ccc"};
List<String> stringList = Arrays.asList(stringArray); 

ただし、上記の書き方だと要素の追加・削除ができない。(参考URL)
要素の追加・削除をする際は下記の通りに記述する。

String[] stringArray = {"aaa", "bbb", "ccc"};
List<String> stringList = new ArrayList<>(Arrays.asList(stringArray));
3
5
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
3
5