記述方法
ArrayListを使う記述方法は、以下の様に<>
の中に格納したい型名を記述します。
Sample.java
import java.util.ArrayList;
public class Sample {
public void main(String[] args) {
ArrayList<String> array = new ArrayList<String>();
}
}
特徴
宣言時のサイズ指定は不要
宣言時にサイズを指定しないため、データを追加しようとした時に自動的に追加されていく。
インスタンスでないものは格納できない
例えばint
型は使えないので、Integer
を使用する。