- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is list interface in Java?
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
public class CollectionsDemo { public static void main(String[] args) { List a1 = new ArrayList(); a1.add("Zara"); a1.add("Mahnaz"); a1.add("Ayan"); System.out.println(" ArrayList Elements"); System.out.print("\t" + a1); List l1 = new LinkedList(); l1.add("Zara"); l1.add("Mahnaz"); l1.add("Ayan"); System.out.println(); System.out.println(" LinkedList Elements"); System.out.print("\t" + l1); } }
Output
ArrayList Elements [Zara, Mahnaz, Ayan] LinkedList Elements [Zara, Mahnaz, Ayan]
- Related Articles
- What are the class implementations of List interface in Java?
- What is Runnable interface in Java?
- What is Callable interface in Java?
- What is a remote interface in java?
- What is Functional Interface in Java 8?
- What is a functional interface in Java?
- What is the generic functional interface in Java?
- List the Interfaces that an Interface Extends in Java
- What is a marker or tagged interface in Java?
- What is the importance of a WindowListener interface in Java?
- What is the importance of a FocusListener interface in Java?
- What does Interface consist of in Java
- What is the difference between Enumeration interface and enum in Java?
- What is the importance of the ProcessHandle interface in Java 9?
- Interface in Java

Advertisements