1.List Usage Scenarios
Characteristics:
① allows repeating elements in the list collection, the Equals method of the element, to compare whether it is a repeating element. 》
② all elements are stored in a linear fashion
Another feature of the ③list collection is that the elements are ordered in order and the order in which the elements are deposited is consistent.
API Introduction:
The Java.util.List interface inherits from the collection interface and is an important branch of a single-column collection.
It is customary to refer to an object that implements the list interface as a list collection. Allows duplicate elements to appear in the list collection.
All elements are stored in a linear fashion, and the specified elements in the collection can be accessed through an index in the program.
Another feature of the list collection is that the elements are ordered, i.e. the order in which the elements are deposited and the order in which they are taken.
Common methods:
-public void Add (int index, E Element): Adds the specified element to the specified position in the collection.
-Public E get (int index): Returns the element at the specified position in the collection.
-Public E Remove (int index): Removes the element from the specified position in the list and returns the removed element.
-Public E Set (int index, E Element): Replaces the element at the specified position in the collection with the specified element, returning the pre-updated element of the value.
⑴arraylist Collection
The structure of the Java.util.ArrayList collection data store is the array structure. Elements are slow to delete, Find Fast,
ArrayList is the most commonly used collection because the most frequently used features in daily development are querying data and traversing data.
At development time, the LinkedList collection can also be used as a stack, and the structure of the queue
Features: Querying data, traversing data
① and delete Slow Find Fast
⑵linkedlist Collection
The structure of the Java.util.LinkedList collection data store is the linked list structure. A collection of convenient elements to add and delete
Features: Easy to add, delete the collection of elements
① and delete fast, find slow
Unique methods:
-public void AddFirst (e E): Inserts the specified element at the beginning of this list.
-public void AddLast (e E): Adds the specified element to the end of this list.
-Public E GetFirst (): Returns the first element of this list.
-Public E GetLast (): Returns the last element of this list.
-Public E Removefirst (): Removes and returns the first element of this list.
-Public E Removelast (): Removes and returns the last element of this list.
-Public E pop (): pops up an element at the stack represented by this list.
-public void push (E E): pushes an element into the stack represented by this list.
-Public Boolean IsEmpty (): Returns True if the list contains no elements.
List of Java usage scenarios