search
HomeJavaJavaBaseWhat is the difference between List and ArrayList in Java?

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment