Home  >  Article  >  Java  >  What is the difference between java array and collection

What is the difference between java array and collection

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-12-27 10:38:174968browse

What is the difference between java array and collection

The difference between java arrays and collections:

1. Arrays can store basic data types and objects, while collections Only objects can be stored in it (basic data types can be stored in the form of wrapper classes).

2. The length of the array is fixed, but the length of the collection can be changed.

3. When defining an array, you must specify the array element type. By default, all elements in the collection are Object.

4. The number of elements actually stored in the array cannot be directly obtained. length is used to obtain the length of the array, but the number of elements actually stored in the collection can be directly obtained through size().

5. Collections have multiple implementation methods and different applicable occasions, unlike arrays which only use continuous space allocation.

6. Collections exist in the form of interfaces and classes. They have the characteristics of encapsulation, inheritance and polymorphism. Various complex operations can be realized through simple method and attribute calls, which greatly improves software development. efficiency.

PHP Chinese website has a large number of free JAVA introductory tutorials, everyone is welcome to learn!

The above is the detailed content of What is the difference between java array and collection. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:java what are annotationsNext article:java what are annotations