Home > Java > javaTutorial > What is the difference between Java collections and arrays?

What is the difference between Java collections and arrays?

WBOY
Release: 2023-04-21 13:49:08
forward
1615 people have browsed it

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]);
 
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template