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

What is the difference between Java collections and arrays?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-04-21 13:49:08
forward
1653 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:
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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template