ArrayList集合类

Arraylist集合类在util包下

用于储存对象的类,可以储存不限定个数的对象

注意:ArrayList<int> array = new ArrayList<int>();这是错误的,因为ArrayList集合必须是一种对象,而int是一种基本数据类型

在数组列表中也可以使用foreach来遍历集合

将数组转换为数组列表的案列

     String[] array = {"red","blue","yellow"};
        ArrayList<String> l = new ArrayList<>(Arrays.asList(array));

将数组列表转换为数组的案列

     ArrayList<String> l = new ArrayList<>();
        String[] arr = new String[l. size()];
        l.toArray(arr) ;

java中的三种长度表达方式:

  数组.length

  字符串.length()

  集合.size()

ArrayList继承了collection接口,要想使用接口,就得实现向下转型,详细内容见收藏

猜你喜欢

转载自www.cnblogs.com/BatmanY/p/9218284.html