

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How does a list work in Java?
public interface List<E> extends Collection<E>
The List interface extends Collection and declares the behavior of a collection that stores a sequence of elements.
Elements can be inserted or accessed by their position in the list, using a zero-based index.
A list may contain duplicate elements.
In addition to the methods defined by Collection, List defines some of its own, which are summarized in the following table.
Several of the list methods will throw an UnsupportedOperationException if the collection cannot be modified, and a ClassCastException is generated when one object is incompatible with another.
Example
The above interface has been implemented in various classes like ArrayList or LinkedList, etc. Following is the example to explain few methods from various class implementation of the above collection methods −
package com.tutorialspoint; import java.util.*; public class CollectionsDemo { public static void main(String[] args) { List<String> a1 = new ArrayList<>(); a1.add("Zara"); a1.add("Mahnaz"); a1.add("Ayan"); System.out.println("ArrayList: " + a1); List<String> l1 = new LinkedList<>(); l1.add("Zara"); l1.add("Mahnaz"); l1.add("Ayan"); l1.remove(1); System.out.println("LinkedList: " + l1); } }
Output
This will produce the following result −
ArrayList: [Zara, Mahnaz, Ayan] LinkedList: [Zara, Ayan]
- Related Questions & Answers
- How does a ClassLoader work in Java?
- How does * operator work on list in Python?
- How does in operator work on list in Python?
- How does concatenation operator work on list in Python?
- How does repetition operator work on list in Python?
- How does del operator work on list in Python?
- How does a Lens antenna work?
- How does a packet filters work?
- How does a vector work in C++?
- How does jQuery.scrollTop() work?
- How does jQuery.scrollLeft() work?
- How does backpropagation work?
- How does classification work?
- How does RSA work?
- How Does a Message Authentication Code Work?