Abstractions live longer than implementations

In general the more abstract your design the longer it is likely to remain useful. So, since Collection is more abstract that it's sub-interfaces then an API design based on Collection is more likely to remain useful than one based on List.

However, the overarching principle is to use the most appropriate abstraction. So if your collection must support ordered elements then mandate a List, if there are to be no duplicates then mandate a Set, and so on.

A note on generic interface design

Since you're interested in using the Collection interface with generics you may the following helpful. Effective Java by Joshua Bloch recommends the following approach when designing an interface that will rely on generics: Producers Extend, Consumers Super

This is also known as the PECS rule. Essentially, if generic collections that produce data are passed to your class the signature should look like this:

public void pushAll(Collection<? extends E> producerCollection) {}

Thus the input type can be E or any subclass of E (E is defined as both a super- and sub-class of itself in the Java language).

Conversely, a generic collection that is passed in to consume data should have a signature like this:

public void popAll(Collection<? super E> consumerCollection) {}

The method will correctly deal with any superclass of E. Overall, using this approach will make your interface less surprising to your users because you'll be able to pass in Collection<Number> and Collection<Integer> and have them treated correctly.

Answer from Gary on Stack Exchange
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Collection.html
Collection (Java Platform SE 8 )
3 weeks ago - Bags or multisets (unordered collections that may contain duplicate elements) should implement this interface directly. All general-purpose Collection implementation classes (which typically implement Collection indirectly through one of its subinterfaces) should provide two "standard" constructors: a void (no arguments) constructor, which creates an empty collection, and a constructor with a single argument of type Collection, which creates a new collection with the same elements as its argument.
🌐
GeeksforGeeks
geeksforgeeks.org › java › collection-interface-in-java-with-examples
Collection Interface in Java - GeeksforGeeks
Instead, we create an object of the ArrayList class that implements the interface and assign it to the interface reference. The Collection interface is part of a hierarchy that extends Iterable, which means collections can be traversed.
Published   1 week ago
Discussions

programming practices - Is there a good reason to use Java's Collection interface? - Software Engineering Stack Exchange
Does this logic apply to interfaces like java.util.Collection? I would much rather see something like the following: ... In the last case, I don't know what kind of data set I'm dealing with, whereas in the first two instances I can make some assumptions about ordering and uniqueness. More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
November 26, 2010
java - Collection Interface vs arrays - Stack Overflow
The Collection interface is just ... extend Collection. These specialized interfaces and abstract classes provide functionality for working with sets (unique objects), growing arrays (e.g. ArrayList), key-value maps etc -- all of which you cannot do out of the box with an array. However, iterating through an array and setting/reading items from an array remains one of the fastest methods of dealing with data in Java... More on stackoverflow.com
🌐 stackoverflow.com
Java's Collections Framework Gets a Makeover with New Sequenced Collection Types
Looks useful. Though I can't help but wonder if some of these should be split if there is already a need to resort to throwing unsupported operation exceptions. An implementation that throws UOEs is kind of lying about it's contact. It doesn't really implement the whole interface. Sometimes it is the best compromise, but I'm not convinced that is the case here. More on reddit.com
🌐 r/java
35
110
March 14, 2023
Java ImmutableCollection inheriting from Collection interface! Bad decision by Java team?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/java
61
18
July 20, 2023
🌐
Programiz
programiz.com › java-programming › collection-interface
Java Collection Interface
The Collection interface is the root interface of the Java collections framework. There is no direct implementation of this interface. However, it is implemented through its subinterfaces like List, Set, and Queue. For example, the ArrayList class implements the List interface which is a ...
🌐
W3Schools
w3schools.com › java › java_collections.asp
Java Collections Framework
Before we explore ArrayList, HashSet, ... Framework. The Java Collections Framework provides a set of interfaces (like List, Set, and Map) and a set of classes (ArrayList, HashSet, HashMap, etc.) that implement those ...
🌐
Medium
rameshfadatare.medium.com › java-collection-interface-a78ddb3e9e1e
Java Collection Interface. Welcome to the Java Collections… | by Ramesh Fadatare | Medium
September 18, 2024 - The Collection interface is the foundation of the Java Collections Framework. It represents a group of objects, known as elements. This interface is the root of the collection hierarchy and provides a common structure for all collections, allowing ...
Top answer
1 of 3
15

Abstractions live longer than implementations

In general the more abstract your design the longer it is likely to remain useful. So, since Collection is more abstract that it's sub-interfaces then an API design based on Collection is more likely to remain useful than one based on List.

However, the overarching principle is to use the most appropriate abstraction. So if your collection must support ordered elements then mandate a List, if there are to be no duplicates then mandate a Set, and so on.

A note on generic interface design

Since you're interested in using the Collection interface with generics you may the following helpful. Effective Java by Joshua Bloch recommends the following approach when designing an interface that will rely on generics: Producers Extend, Consumers Super

This is also known as the PECS rule. Essentially, if generic collections that produce data are passed to your class the signature should look like this:

public void pushAll(Collection<? extends E> producerCollection) {}

Thus the input type can be E or any subclass of E (E is defined as both a super- and sub-class of itself in the Java language).

Conversely, a generic collection that is passed in to consume data should have a signature like this:

public void popAll(Collection<? super E> consumerCollection) {}

The method will correctly deal with any superclass of E. Overall, using this approach will make your interface less surprising to your users because you'll be able to pass in Collection<Number> and Collection<Integer> and have them treated correctly.

2 of 3
7

The Collection interface, and the most permissive form Collection<?>, is great for parameters that you accept. Based on use in the Java library itself it's more common as a parameter type than a return type.

For return types, I think your point is valid: If people are expected to access it, they should know the order (in the Big-O sense) of the operation being performed. I would iterate over a Collection returned and add it to another Collection, but it would seem a bit crazy to call contains on it, not knowing if it's a O(1), O(log n), or O(n) operation. Of course, just because you have a Set doesn't mean it's a hashset or a sorted set, but at some point you will make assumptions that the interface has been reasonably implemented (and then you'll need to go to plan B if your assumption is shown to be incorrect).

As Tom mentions, sometimes you need to return a Collection in order to maintain encapsulation: You don't want implementation details leaking out, even if you could return something more specific. Or, in the case Tom mentioned, you could return the more specific container, but then you'd have to construct it.

Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › java › java_collection_interface.htm
Java - Collection Interface
Java Vs. C++ ... The Collection interface is the foundation upon which the collections framework is built. It declares the core methods that all collections will have. There are several methods in the Collection interface to perform basic operations ...
🌐
Oracle
docs.oracle.com › javase › tutorial › collections › interfaces › collection.html
The Collection Interface (The Java™ Tutorials > Collections > Interfaces)
In other words, it allows you to convert the collection's type. Suppose, for example, that you have a Collection<String> c, which may be a List, a Set, or another kind of Collection. This idiom creates a new ArrayList (an implementation of the List interface), initially containing all the elements in c.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › collections in java – java collection framework
Collections in Java - Java Collection Framework
September 3, 2024 - ... The collection in java is the root interface of the collection framework and provide several classes and interfaces to represent a group of individual objects as a single unit.
Top answer
1 of 5
77

The easy way to think of it is: Collections beat object arrays in basically every single way. Consider:

  • A collection can be mutable or immutable. A nonempty array must always be mutable.
  • A collection can allow or disallow null elements. An array must always permit null elements.
  • A collection can be thread-safe; even concurrent. An array is never safe to publish to multiple threads.
  • A list or set's equals, hashCode and toString methods do what users expect; on an array they are a common source of bugs.
  • A collection is type-safe; an array is not. Because arrays "fake" covariance, ArrayStoreException can result at runtime.
  • A collection can hold a non-reifiable type (e.g. List<Class<? extends E>> or List<Optional<T>>). An array will generate a warning for this.
  • A collection can have views (unmodifiable, subList...). No such luck for an array.
  • A collection has a full-fledged API; an array has only set-at-index, get-at-index, length and clone.
  • Type-use annotations like @Nullable are very confusing with arrays. I promise you can't guess what @A String @B [] @C [] means.
  • Because of all the reasons above, third-party utility libraries should not bother adding much additional support for arrays, focusing only on collections, so you also have a network effect.

Object arrays will never be first-class citizens in Java APIs.

A couple of the reasons above are covered -- but in much greater detail -- in Effective Java, Third Edition, Item 28, from page 126.

So, why would you ever use object arrays?

  • You're very tightly optimizing something
  • You have to interact with an API that uses them and you can't fix it
    • so convert to/from a List as close to that API as you can
  • Because varargs (but varargs is overused)
    • so ... same as previous
  • Obviously some collection implementations must be using them
  • I can't think of any other reasons, they suck bad
2 of 5
6

It's basically a question of the desired level of abstraction.

Most collections can be implemented in terms of arrays, but they provide many more methods on top of it for your convenience. Most collection implementations I know of for instance, can grow and shrink according to demand, or perform other "high-level" operations which basic arrays can't.

Suppose for instance that you're loading strings from a file. You don't know how many new-line characters the file contains, thus you don't know what size to use when allocating the array. Therefore an ArrayList is a better choice.

🌐
Quora
quora.com › What-is-the-Java-collections-framework-and-its-main-interfaces
What is the Java collections framework and its main interfaces? - Quora
Collection interface extends all the methods from Iterable interface, providing new methods for operations on data structures, e.g., methods to find or remove an element in the data structure.
🌐
Educative
educative.io › blog › what-are-java-collections
What are Java Collections? Get started with the framework
March 6, 2025 - Interfaces: These interfaces supply the abstract data type to represent the collection. The java.util.Collection is the root interface of the framework.
🌐
Medium
medium.com › @reetesh043 › java-collection-list-interface-7b8cc69f2a5a
Java Collection: List Interface. Introduction | by Reetesh Kumar | Medium
January 24, 2024 - The List interface in Java is a fundamental component of the Java Collections Framework, designed to represent an ordered collection of elements. Lists allow duplicate elements and maintain the insertion order.
🌐
freeCodeCamp
freecodecamp.org › news › java-collections-framework-reference-guide
How to Use the Java Collections Framework – A Guide for Developers
January 28, 2025 - The Collection interface extends the Iterable interface. This means it inherits the properties and behavior of the Iterable interface and adds its own behavior for adding, removing, and retrieving elements.
🌐
GeeksforGeeks
geeksforgeeks.org › java › collection-vs-collections-in-java-with-example
Collection vs Collections in Java with Example - GeeksforGeeks
Collection: Collection is a interface present in java.util package. It is used to represent a group of individual objects as a single unit. It is similar to the container in the C++ language.
Published   July 15, 2025
🌐
Jenkov
jenkov.com › tutorials › java-collections › collection.html
Java Collection
March 14, 2019 - The Java Collection interface is the root interface for List, Set and several other interfaces in the Java Collections API. This Java Collection interface tutorial explains its role and its core methods.
🌐
findnerd
findnerd.com › list › view › Collection-Framework-and-Interface-in-Java- › 28529
Collection Framework and Interface in Java
February 3, 2017 - In java “collections” helps us to store and manipulate the collection of objects. all the operations such as manipulation, deletion, searching, sorting, insertion can be performed quickly with the help of “collections”. java collection ...
🌐
Simplilearn
simplilearn.com › home › resources › software development › java tutorial for beginners › collections in java and how to implement them?
Collections in Java: A Complete Beginner's Guide
May 4, 2025 - Java Collections are the one-stop solutions for all the data manipulation jobs such as storing data, searching, sorting, insertion.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Baeldung
baeldung.com › home › java › java collections › choosing the right java collection
Choosing the Right Java Collection | Baeldung
April 3, 2025 - Here’s the diagram for interface relationships in the Java library: Any concrete collection implementation (collection class) is derived from one of the collection interfaces. The semantics of collection classes are defined by their interfaces, as concrete collections provide specific implementations for operations that their parent interfaces define.
🌐
HCL GUVI
studytonight.com › java › collection-interfaces.php
Interfaces in Java Collection Framework
Comes with a built-in debugger to fix code errors. Supports JavaScript, Python, Ruby, and 20+ programming languages.Explore IDE