Home >Java >javaTutorial >What is the difference between Java collections and arrays?
1. Arrays can not only store basic data types, but also store values of basic data types, and reference data types store address values;
Collections can only store reference data. Type (object), basic data types can also be stored in collections, but they will be automatically packaged (new feature of JDK1.5) into objects when stored.
2. The length of the array is fixed and cannot be increased automatically;
The length of the collection is variable and can be increased according to the increase of elements.
3. Conversion of arrays and collections
int[] arr = {1,3,4,6,6}; Arrays.asList(arr); for(int i=0;i<arr.length;i++){ System.out.println(arr[i]); }
The above is the detailed content of What is the difference between Java collections and arrays?. For more information, please follow other related articles on the PHP Chinese website!