🌐
GeeksforGeeks
geeksforgeeks.org › java › collection-interface-in-java-with-examples
Collection Interface in Java - GeeksforGeeks
The Collection interface is the root of the Java Collections Framework, defined in the java.util package. It represents a group of individual objects as a single unit and provides basic operations for working with them. Dynamic in Nature: Collections can automatically grow or shrink in size, unlike arrays that have a fixed length. Stores Homogeneous Objects: With generics, collections store elements of a specified type...
Published   5 days ago
🌐
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.
🌐
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 on collections. For example, adding, removing, and querying elements/objects. The following is the list of ...
🌐
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.
🌐
Programiz
programiz.com › java-programming › collection-interface
Java Collection Interface
The List interface is an ordered collection that allows us to add and remove elements like an array. To learn more, visit: Java List Interface. The Set interface allows us to store elements in different sets similar to the set in mathematics. It cannot have duplicate elements.
🌐
Oracle
docs.oracle.com › javase › tutorial › collections › interfaces › index.html
Lesson: Interfaces (The Java™ Tutorials > Collections)
The Collection interface is the least common denominator that all collections implement and is used to pass collections around and to manipulate them when maximum generality is desired. Some types of collections allow duplicate elements, and others do not. Some are ordered and others are unordered. The Java platform doesn't provide any direct implementations of this interface but provides implementations of more specific subinterfaces, such as Set and List.
🌐
DataFlair
data-flair.training › blogs › collections-in-java
Collections in Java - Types of Interface In Java - DataFlair
November 6, 2024 - What are Collections in Java-Types of Interface in Java: Set, List, Map, Subtypes of Java Collection: Deque, Java Line, Java Stack etc.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-collection-tutorial
Collections in Java
June 11, 2024 - Java provides collection interfaces like List, Set, Map, and Queue, with ready-made classes such as ArrayList, HashSet, HashMap, and PriorityQueue, so you don’t have to write data-handling code from scratch.
🌐
Wikipedia
en.wikipedia.org › wiki › Java_collections_framework
Java collections framework - Wikipedia
October 20, 2025 - One example of a key is an identification card. The base interface for dictionaries/maps is called Map. Lists are finite collections where it can store the same value multiple times. Sets are unordered collections that can be iterated and contain each element at most once. The base interface for sets is called Set. Lists are implemented in the collections framework via the java.util.Listinterface.
Find elsewhere
🌐
ByteByteGo
bytebytego.com › guides › java-collection-hierarchy
ByteByteGo | Java Collection Hierarchy
The Collection interface has three main subinterfaces: List, Set, and Queue. Each of these interfaces has its unique characteristics and use cases. Java engineers need to be familiar with the Java Collection hierarchy to make informed decisions ...
🌐
GeeksforGeeks
geeksforgeeks.org › collections-in-java-2
Collections in Java - GeeksforGeeks
List <T> al = new ArrayList<> (); List <T> ll = new LinkedList<> (); List <T> v = new Vector<> (); Where T is the type of the object · The classes which implement the List interface are as follows: ArrayList provides us with dynamic arrays in Java. Though, it may be slower than standard arrays but can be helpful in programs where lots of manipulation in the array is needed. The size of an ArrayList is increased automatically if the collection grows or shrinks if the objects are removed from the collection.
Published   March 21, 2025
🌐
Javatpoint
javatpoint.com › collections-in-java
Collections in Java - javatpoint
October 20, 2013 - Collections in java or collection framework in java with List, Set, Queue and Map implementation, hierarchy and methods of Java Collections framework, ArrayList, LinkedList, HashSet, LinkedHashSet, TreeSet, HashMap, LinkedHashMap, TreeMap, PriorityQueue, ArrayDeque.
🌐
Tpoint Tech
tpointtech.com › collections-in-java
Collections in Java - Tpoint Tech
February 12, 2026 - Java Collection means a single unit of objects. Java Collection framework provides many interfaces (Set, List, Queue, Deque) and classes (ArrayList, Vector, LinkedList, PriorityQueue, HashSet, LinkedHashSet, TreeSet).
🌐
Tutorialspoint
tutorialspoint.com › java › java_collections.htm
Java - Collections Framework
In addition to collections, the framework defines several map interfaces and classes. Maps store key/value pairs. Although maps are not collections in the proper use of the term, but they are fully integrated with collections. All classes and interfaces for the collection framework are available in java.utli package.
Top answer
1 of 5
2

1) Yes.

Method parameters should be as general as possible. List<? extends A> is more general than List<A>, and can be used when you don't need to add things to the list. If you were only adding to the list (and not reading from it), the most general signature would probably be List<? super A>

Conversely, method return types should be as specific as possible. You rarely to never want to return a wildcard generic from a method.

Sometimes this can lead to generic signatures:

<T extends MyObject> List<T> filterMyObjects(List<T>)

This signature is both as specific and as general as possible

2) Yes, except possibly in some rare very specific cases (I'm thinking of BitSet, although that isn't technically a Collection).

2 of 5
1

If you declare your list as List<? extends A>, then you can pass in any object which static type is List<X>, where X extends A if A is a class, or X implements A id A is an interface. But you'll not be able to pass in a List or a List<Object> to it (unless A is Object) without force-casting it.

However, if you declare the parameter as a List<A>, you'll only be able to pass lists which static type is strictly equivalent to List<A>, so not List<X> for instance. And by "you are not able to do otherwise", I really mean "unless you force the compiler to shut up and accept it", which I believe one should not do unless dealing with legacy code.

Collections are really collections of references. The abstraction actually is that everything you can put in a variable is a reference to something, unless that variable is of a primitive type.

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.

🌐
IIT Kanpur
iitk.ac.in › esc101 › 05Aug › tutorial › collections › interfaces › index.html
Interfaces
See the section The Set Interface. List: An ordered collection (sometimes called a sequence). Lists can contain duplicate elements. The user of a List generally has precise control over where in the List each element is inserted, and can access elements by their integer index (position).
🌐
DigitalOcean
digitalocean.com › community › tutorials › collections-in-java-tutorial
Java Collections Tutorial: List, Set, Map & Queue | DigitalOcean
August 3, 2022 - Better Quality – Using core collection classes that are well-tested increases our program quality rather than using any home-developed data structure. ... Reduce effort to maintain because everybody knows Collection API classes. Java collection interfaces are the foundation of the Java Collections Framework. Note that all the core collection interfaces are generic; for example public interface Collection<E>. The <E> syntax is for Generics and when we declare Collection, we should use it to specify the type of Object it can contain.
🌐
Eur
feb22012.ese.eur.nl › week5 › 2-collection-interfaces
The Collection and Iterable interfaces - Programming
ArrayList is the most commonly used implementation of the List, but there are others. The List interface is a subtype of the Collection interface, and the Collection interface itself is a subtype of the Iterable interface. Also, the Set interface and List interface are sub-types of the Collection ...
🌐
freeCodeCamp
freecodecamp.org › news › java-collections-framework-reference-guide
How to Use the Java Collections Framework – A Guide for Developers
January 28, 2025 - In the Java Collections Framework, various collection interfaces like Set, List, and Queue extend the Collection interface, and they must adhere to the contract defined by the Collection interface.