Home > Java > JavaBase > body text

What is the difference between List and ArrayList in Java?

Guanhui
Release: 2020-06-08 13:29:56
Original
7130 people have browsed it

What is the difference between List and ArrayList in Java?

What is the difference between List and ArrayList in Java?

List is an interface and implements the Collection interface, so the List interface has all the common methods provided by the Collection interface, and ArrayList is a dynamic number that implements the Collection and List interfaces.

List features

  • Duplicate elements are allowed in the List collection "Through the equals method of the element, to compare whether they are duplicate elements. 》

  • All elements are stored in a linear manner

  • Another feature of the List collection is that the elements are stored in an orderly manner. The order is the same as the order of removal.

List API introduction

The java.util.List interface inherits from the Collection interface and is an important branch of single-column collections,

It is customary to call objects that implement the List interface a List collection. Duplicate elements are allowed in the List collection.

All elements are stored in a linear manner. Specified elements in the collection can be accessed through indexes in the program.

In addition, another feature of the List collection is that the elements are ordered, that is, the order in which the elements are stored is consistent with the order in which they are taken out.

List common methods

  • #- public void add(int index, E element): Add the specified element to the collection on the specified location.

  • - public E get(int index): Returns the element at the specified position in the collection.

  • - public E remove(int index): Remove the element at the specified position in the list, and return the removed element.

  • - public E set(int index, E element): Replace the element at the specified position in the set with the specified element, and return the element before the value is updated.

Recommended tutorial: "Java"

The above is the detailed content of What is the difference between List and ArrayList in Java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!