DEV Community

vishnu vishnu
vishnu vishnu

Posted on

List in Java

What is a List?

  • List is an interface in the Java Collection Framework that stores an ordered collection of elements and allows duplicates, and elements can be accessed by their index. *Maintains insertion order. *Allows duplicate elements. *Supports index-based access.

Why List?

-1. Order is Important

Data should maintain insertion order.

  1. Duplicates Are Allowed

Example: Same product added twice in the cart.

  1. Index-Based Access Needed

You can access elements using an index:

When List?

  • When the number of elements is unknown
  • When duplicates are allowed
  • When we need ordered data
  • When we need index-based operations

*** Real-Time Examples

  • E-commerce Cart

Use List → Products in cart (order matters)

  • Student Marks

Store multiple marks (duplicates allowed)

  • Log History

Maintain insertion order

Top comments (0)