An ordered collection (also known as a sequence ). Users of this interface can precisely control the insertion position of each element in the list. The user can access the element based on the integer index of the element (where it is located in the list) and search for the elements in the list.
Unlike set, a list usually allows repeating elements. More specifically, lists generally allow for e1.equals (E2) elements to E1 and E2, and if the list itself allows null elements, they usually allow multiple null elements. It's hard to avoid repeating lists by throwing a run-time exception when a user tries to insert a repeating element, but we hope that the less you can use it, the better.
List interface in iterator,add,remove,equals , and hashcode The contract for the method is added with some additional conventions that exceed the conventions specified in the Collection interface. For convenience, the declarations for other inherited methods are also included here.
The list interface provides 4 ways to locate (index) a list element. The list (like a Java array) is based on 0. Note that these operations may be performed in a time proportional to the index values of some implementations, such as the LinkedList class. Therefore, if the caller does not know the implementation, then iterating over the list element is usually better than iterating through the list with an index.
The List interface provides a special iterator, called Listiterator, that allows element insertion and substitution, as well as bidirectional access, in addition to the normal operation that the Iterator interface provides. It also provides a way to get a list iterator starting at the specified position in the list.
The List interface provides two ways to search for a specified object. From a performance standpoint, these methods should be used with care. In many implementations, they perform a high-overhead linear search.
The list interface provides two ways to efficiently insert and remove multiple elements at any point in the list.
Note: Although the list allows itself to be included as an element, it is recommended to be particularly cautious: on such lists, theequals and hashcode methods are no longer well-defined.
Some list implementations have restrictions on the elements that a list may contain. For example, some implementations prohibit null elements, while some implementations have restrictions on the types of elements. Attempting to add an unqualified element throws an unchecked exception, usually nullpointerexception or classcastexception. Attempts to query for the presence of unqualified elements may throw an exception, or it may simply return false; Some implementations take the previous behavior, while others use the latter. In a nutshell, when trying to perform an action on an unqualified element, if the operation does not result in an unqualified element being inserted into the list, the operation may throw an exception or succeed, depending on the choice of implementation. The specification for this interface marks such exceptions as "optional."
This interface is a member of the Java collections Framework.