Both collections and containers are containers in Java.
the difference
Array features: fixed size, can only store data of the same data type
Collection features: the size can be dynamically expanded, and various types of data can be stored
convert
Convert an array to a collection:
Arrays.asList(array)
Example:
int[] arr = {1,3,4,6,6}; Arrays.asList(arr); for(int i=0;i<arr.length;i++){ System.out.println(arr[i]); }
Convert a collection to an array:
collection.toArray();
Example:
List list = new ArrayList(); list.add("a"); list.add("b"); list.toArray(); System.out.println(list.toString());