ArrayList<Integer> lt = new ArrayList<>(); // List<Integer> lt = new LinkedList<>();

来源:互联网 发布:细说php第三版pdf 编辑:程序博客网 时间:2024/06/05 14:31

1.新建一个数组

//元素类型 [] 数组名 = new 元素类型[元素个数或数组长度];

int[] arr = new int[4];

//以下是两种声明数组

int[] arr = new int[]{3,5,6,7};
int[] arr = {3,5,6};

赋值是 :arr[0]=89;

读取的时候是arr[0]




关于这两个的区别:

前者是都是一个类。

后者是编译时的是父类ArrayLIstanbul类    运行的时候是ArrayList类   多态


  ArrayList<Integer> lt = new ArrayList<>();      List<Integer> lt = new ArrayList<>();

0 0
原创粉丝点击