Detailed explanation of Java list usage examples

Detailed explanation of Java list usage examples

The principle of variable array in Java is to constantly create new arrays and add the original array to the new array. The usage of Java list is explained in detail below.

List: unique methods. All methods that can operate corner markers are unique to the system

Deletes the element at the specified location

Modify the element of the specified corner mark. Set (int index, e element) returns the modified element

check

List collection specific iterator: listiterator (which is a sub interface of iterator)

be careful:

During iteration, the elements in the collection cannot be operated through the methods of the collection object, because the concurrentmodificationexception exception (concurrent exception) will occur. Therefore, in the iterator, the iterator method can only be used to create elements. Because the iterator method is limited, it can only judge, take out and delete elements. If you want other operations, such as adding, To modify, you need to use its sub interface, which can only be obtained through the listiterator method of the list collection

Vector: enumeration is the unique extraction method of vector. It is very similar to iterators (in fact, enumeration and iteration are the same) and has been replaced by iterators

LinkedList:

Unique methods:

addFirst(); Add element to header

addLast(); Add element at tail

getFirst(); getLast();

Gets the element but does not delete it. If there are no elements in the collection, NoSuchElementException occurs

removeFirst(); removeLast();

Gets the element but deletes it. If there are no elements in the collection, NoSuchElementException occurs

At jdk1 6 alternative methods have emerged

offerFirst(); offerLast();

peekFirst(); peekLast(); Gets the element, but the element is not deleted. If there are no elements in the collection, null is returned

pollFirst(); pollLast(); Gets the element, but the element is deleted. If there are no elements in the collection, null is returned

If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>