Comparison of arrays and collections

Comparison of arrays and collections

For the fixed length of arrays in Java, Java proposes a collection framework, which implements a variable-length storage data container—collection [volume and current number of elements]

Arrays are not object-oriented and have obvious shortcomings. Collections make up for the shortcomings of arrays, and are more flexible and practical than arrays, and different collection framework classes can be used in different situations. as follows:

  • Arrays can store basic data types and objects, while collections store references to objects, not the objects themselves
  • The capacity of the array is fixed and cannot be changed dynamically, and the capacity of the collection class changes dynamically
  • The array cannot determine how many elements are actually stored in it, length only tells the capacity of the array, and the size() of the collection can exactly know the number of elements
  • There are multiple implementations of collections and different applicable occasions, unlike arrays that only use sequential tables
  • Collections exist in the form of classes and have the characteristics of encapsulation, inheritance, polymorphism and other classes. Various complex operations can be realized through simple methods and attributes, which greatly improves the efficiency of software development.

Guess you like

Origin blog.csdn.net/qq_45874107/article/details/114265309