Home  >  Article  >  Java  >  What are the common methods of list collection in Java?

What are the common methods of list collection in Java?

王林
王林Original
2019-11-18 14:00:135166browse

What are the common methods of list collection in Java?

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.

What are the common methods of list collection in Java?

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.

What are the common methods of list collection in Java?

3. E get(int index)

Returns the element at the specified index position in the list collection.

What are the common methods of list collection in Java?

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

What are the common methods of list collection in Java?

5, E remove(int index)

Delete the specified index Object

What are the common methods of list collection in Java?

6、E set(int index, E element)

The element at the index position is changed to element Element

What are the common methods of list collection in Java?

7、List subList(int fromIndex, int toIndex)

Returns the element from index fromIndex to toIndex Collection, including left but not right

What are the common methods of list collection in Java?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn