1. Why use a collection framework
When we don’t know how many objects will be needed when the program is running, or we need to store objects more complicated -we can use the Java set framework
2. The content contained in the Java collection framework
Interface: (parent class) The List (subclass) interface and SET (subclass) under the Collection interface
Under the interface List interface, it contains (ArrayList set implementation classes and linkedlist set implementation classes))
Under the set interface, it contains (Hashset Collection Implementation Class and TreeSet Collection Implementation Class))
Interface: (parent class) Map interface contains (HashMap collection implementation class and TreeMap collection implementation class)
*Collections interface provides a variety of algorithms such as sorting, traversal, etc.*Java collection framework provides us with an interface and class with excellent performance and convenient use. They are located in the java.util package
3. The characteristics of Collection, List and Set:
The Collection interface stores a set of unique and disorderly objects
List interface storage a set of uniquely, orderly (insert order) objects
The SET interface storage a set of unique, disorderly object MAP interface stores a set of key value objects, providing a mapping from key to value
4. The advantages of the collection of ArrayList and LinkedList
1. ArrayList implements a variable array in length, allocating continuous space in memory. The efficiency of traversal elements and random access elements is relatively high
2. LinkedList adopts a linked list storage method. The efficiency is relatively high when inserting and deleting elements
List interface provides the corresponding method Remove (), contains (), just use it directly
Common method of list interface:
Boolean add (Object O) adds elements at the end of the list, and the starting index position starts from 0
Void add (int interject O) adds elements to the specified index position. The index position must be between the number of elements in 0 and list
Int size () Return the number of elements in the list
Object get (int index) returns elements at the specified index position. The element taken out is Object type, and a compulsory type conversion needs to be performed before use
Boolean contains (Object O) determine whether there are specified elements in the list
Boolean Remove (Object O) delete elements from the list
Object Remove (int index) delete the specified position element from the list, and the starting index position starts from 0
Special method of linkedList
VOID Addfirst (Object O) The first added element of the list
Void AddLast (Object O) adds elements at the end of the list
Object Getfirst () Return the first element in the list
Object Getlast () Return the last element in the list
Object Removefirst () Delete and return the first element in the list
Object Removelast () delete and return the last element in the list
MAP interface commonly used methods:
Object Put (Object Key, Object Val) stores in a "key-value pair" manner
Object Get (Object Key) returns the associated value according to the key, if there is no specified key, return NULL
Object Remove (Object Key) delete the "key-value pair" mapping by the specified key
int size () returns the number of elements
Set keyset () Return to the collection of the key
Collection of the return value of Collection Values ()
Boolean Containskey (Object Key) If there is a "key-value pair" mapping by the specified key, return True