The List interface inherits the Collection interface, so some methods in the Collection collection are also inherited by the List collection.
Common methods for List collections:
1. void add(int index, E element)
Insert at the specified position element, and all subsequent elements are moved back one element.
2、boolean addAll(int index, Collection extends E> c)
Insert c in the specified position Collection of all elements, if the collection changes, returns true, otherwise returns false.
It means that when the inserted set c has no elements, then false is returned. If the set c has elements and the insertion is successful, then true is returned.
3. E get(int index)
Returns the element at the specified index position in the list collection.
4. int indexOf(Object o)
Returns the index position of the first occurrence of o object in the list collection, if There is no o object in the list collection, then -1
5, E remove(int index)
Delete the specified index Object
6、E set(int index, E element)
The element at the index position is changed to element Element
7、List
Returns the element from index fromIndex to toIndex Collection, including left but not right
Recommended tutorial:Java tutorial
The above is the detailed content of What are the common methods of list collection in Java?. For more information, please follow other related articles on the PHP Chinese website!