Simple idea of set

Time:2020-9-3

1、 The origin of set

If we want to manipulate many objects, we need to store many objects. At this time, we will think that we have learned about arrays, so we can put custom objects into arrays.

Why don’t we use arrays to store objects? Because the array length is fixed, and we are often uncertain about the number of objects. So we have a collection framework, which is used to store objects.

1. The difference between collection and array

A: The length of the collection is variable. The basic data type value cannot be stored in the collection, only objects can be stored.

B: The length of the array is fixed and can store objects and basic data types.

When and which?

The length is not fixed, use set.

Fixed length, can be set, available array.

2Architecture of collections

Because each container has a different data structure, there are many kinds of containers in our collection framework. At this time, we continue to extract the container upward, and finally form a collection architecture.

Collection

          |–List

              |–ArrayList

              |–Vector

              |–LinkedList

         |–Set

              |–HashSet

              |–TreeSet

Our general habit of learning system is: first learn the top object, then use the bottom object.