44. Difference between collection and array

1. Array

  Definition: A collection container that stores a data type

  

  Features of arrays:

      1. Only one data type of data can be stored

      2. Once the array is initialized, the length is fixed

      3. The memory addresses of the elements in the array are consecutive between the elements

 

  Note: Arrays of type Object can store any type of data

 

2. Collection

  Definition: A collection is a collection container that stores object data.

  

  Advantages of sets over arrays:

      1. Collections can store data of any type, while arrays can only store data of one data type

      2. The length of the collection is not fixed, and the length of the array is fixed

 

3. Division of collections

  ---------------| Collection The root interface of a singleton collection

  ----------| List If it is a collection class that implements the list interface, it has specific characteristics: ordered, repeatable

  ----------| Set If a collection class that implements the set interface, it has the characteristics: unordered, non-repeatable    

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325070384&siteId=291194637