Array and ArratList区别

来源:互联网 发布:中国的战争潜力 知乎 编辑:程序博客网 时间:2024/06/04 19:33
10. Difference between Array and ArrayListArrayList can hold primitive variable(the primitive variable will automatically wrap and unwrap when place in/out ArrayList),Array can hold primitive variableArraylist 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'tArray has to know the size at time it is created, ArrayList not needTo 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");