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是一个类。但在这个脚本中,当我尝试使用int而不是Integer时,我会得到'索引超出范围异常'错误。 我以前使用int创建数组,那么int数组和Integer数组有什么区别?谢谢。