| 10. Difference between Array and ArrayList |
| ArrayList can hold primitive variable(the primitive variable will automatically wrap and unwrap when place in/out ArrayList),Array can hold primitive variable |
| Arraylist has a lot method(Remove, Add, Contains, IsEmpty, indexof, size, get), Array(can use length variable to get the length of an Array) |
| ArrayList can shrink when remove some elem, but Array can't |
| Array has to know the size at time it is created, ArrayList not need |
| To put an object in an Array, you need assign it to a specific location, ArrayList not need |
ArrayList<String> myList=new ArrayList<String>();
String [] myString=new String[7];
String a=new String("whooo");
myList.add(a);
String a=new String("hiihi");
本文详细对比了Array与ArrayList之间的主要区别:ArrayList可以自动装箱拆箱处理基本类型,提供更多内置方法如添加、删除等;ArrayList可以在移除元素后自动收缩大小,而Array不可以;Array在创建时需要指定大小,ArrayList则不需要;向Array中添加对象需要指定位置,ArrayList则不需要。
2714

被折叠的 条评论
为什么被折叠?



