Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6812381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:26:32+00:00 2026-05-26T20:26:32+00:00

An ArrayList, a List and a Collection in Java behaves almost in the same

  • 0

An ArrayList, a List and a Collection in Java behaves almost in the same way and they have many methods in common. If such is a case then, what are the major differences among them? The following simple code snippet demonstrates it.

package collections;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

final public class Main
{
    public static void main(String[] args) 
    {
        Collection<String> collection=new ArrayList<String>();
        List<String>list=new ArrayList<String>();
        ArrayList<String>arrayList=new ArrayList<String>();        

        collection.add("A");
        collection.add("B");

        list.add("A");
        list.add("B");

        arrayList.add("A");
        arrayList.add("B");

        Iterator<String>collectionIterator=collection.iterator();
        Iterator<String>listIterator=list.iterator();
        Iterator<String>arrayListIterator=arrayList.iterator();

        while(collectionIterator.hasNext())
        {
            System.out.println(collectionIterator.next());
        }

        while(listIterator.hasNext())
        {
            System.out.println(listIterator.next());
        }

        while(arrayListIterator.hasNext())
        {
            System.out.println(arrayListIterator.next());
        }
    }
}

When and where to use an ArrayList, a Collection and a List? In which specific situations, the differences among them may be remarkable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:26:32+00:00Added an answer on May 26, 2026 at 8:26 pm

    A Collection is an interface that defines the highest-level of shared collection behavior, and extends Iterable (which just defines the iterator() method).

    A List is an interface that defines the highest-level of shared List behavior.

    ArrayList is an implementation of List and in general wouldn’t be used in a declaration unless you need an implementation guarantee (e.g., fast indexed access), but is fine to use as a list value.

    Read the docs to see the differences–they’re described in the API. The implementation (ArrayList) will have a type-specific implementation of each method in each interface it implements.

    In general, use the least-specific interface that provides what you need. For example, passing Collection instead of List allows a wider selection of implementations. If you need something like indexed access (e.g., List.get(int)), a Collection wouldn’t work.

    As with most things, which to use depends entirely upon your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java collection: Collection<CustomObject> list = new ArrayList<CustomObject>(); CustomObject has an id
So in java the way to initialise an interface, such as a collection or
import java.util.Arrays; import java.util.ArrayList; import java.util.Scanner; import java.util.Collections; import java.util.List; public class TennisTournament {
I have a collection (or list or array list) in which I want to
I have a Arraylist List<?> myList=new ArrayList(); myList = fetchQuery(); //fetches the list of
So i have this ArrayList: list.get(0) == love list.get(1) == foo list.get(2) == make
I have problem adding arraylist to list view, will explain about my problem here..
I have a list (an ArrayList , infact) of type HColumn<ColName, ColValue> . Now
Possible Duplicate: Sorting a collection of objects How to sort the list in java
I have java API which return this type: ArrayList[ArrayList[String]] = Foo.someJavaMethod() In scala program,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.