import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
public class arraysAsList {
public static void main(String[] args) {
String [] arrayA = {"Box","Sun","Clock","Phone"};
Integer [] arrayB = {21,27,24,7};
List listStructureA = new ArrayList();
List listStructureB = new ArrayList();
listStructureA = Arrays.asList(arrayA);
listStructureB = Arrays.asList(arrayB);
System.out.println("My first list : " + listStructureA);
System.out.println("Sun = " + listStructureA.get(1));
System.out.println("My second list : " + listStructureB);
System.out.println("24 = " + listStructureB.get(2));
}
}
int はプリミティブ型で、Integer はクラスです。しかし、このスクリプトでは、Integer の代わりに int を使用しようとすると、「index out of bounds exception」エラーが発生します。以前は int を使用して配列を作成していましたが、int 配列と Integer 配列の違いは何ですか? 前もって感謝します。