Methods of implementing classes ArrayList and LinkedList of Java collection
List of methods for list
The following is a simple example:
Implementation class ArrayList
Implementation class LinkedList
The linked list implementation of the list interface implements all optional list operations and allows all elements (including null). In addition to implementing the list interface, the LinkedList class also provides a unified naming method for get, remove and insert elements at the beginning and end of the list. These operations allow the linked list to be used as a stack, queue, or double ended queue.
Some methods of LinkedList
Traversal of sets
As mentioned in the above example, let's look at the code
Using the for loop
Use the for - each loop
Using the iterator interface
Each collection class provides an iterator method to return an iterator. Through this iterator, you can complete the traversal or deletion of the collection. The use steps of the iterator are as follows:
****
1. Obtain the iterator of the set through the iterator method
2. Determine whether the next element exists by calling the hasnext method
3. Use the next method to remove its next element
The method of implementing ArrayList and LinkedList in the above Java collection is all the content shared by Xiaobian. I hope it can give you a reference and support more programming tips.