Similarities and Differences Between java Collections and Arrays

  • 2021-07-18 07:53:04
  • OfStack

Array:

Arrays can be used to hold data of multiple basic data types, and can also be used to hold multiple objects. The length of the array is immutable, and 1 specifies the length of the array when it is initialized (either statically or dynamically). Arrays cannot hold data with mappings.

Collection:

Collections are only used to store objects with different numbers. The length of the collection is variable. Collection can hold data with mapping relationship.

Similarities:

Arrays and collections are similar to containers.

Differences:

The length of the array is fixed and the length of the collection is variable. Arrays can only store objects of the same type, while collections can store objects of different types. Collection can only store objects, not basic types

Summarize


Related articles: