What is the main difference between Collection and Collections in Java?

JavaCollections

Java Problem Overview


What is the main difference between Collection and Collections in Java?

Java Solutions


Solution 1 - Java

Collection is a base interface for most collection classes, whereas Collections is a utility class. I recommend you read the documentation.

Solution 2 - Java

Are you asking about the http://java.sun.com/javase/6/docs/api/java/util/Collections.html">Collections</a> class versus the classes which implement the http://java.sun.com/javase/6/docs/api/java/util/Collection.html">Collection</a> interface?

If so, the Collections class is a utility class having static methods for doing operations on objects of classes which implement the Collection interface. For example, Collections has methods for finding the max element in a Collection.

The Collection interface defines methods common to structures which hold other objects. List and Set are subinterfaces of Collection, and ArrayList and HashSet are examples of concrete collections.

Solution 3 - Java

collection : A collection(with small 'c') represents a group of objects/elements.

Collection : The root interface of Java Collections Framework.

Collections : A utility class that is a member of the Java Collections Framework.

Solution 4 - Java

Collection, as its javadoc says is "The root interface in the collection hierarchy." This means that every single class implementing Collection in any form is part of the Java Collections Framework.

The Collections Framework is Java's native implementation of data structure classes (with implementation specific properties) which represent a group of objects which are somehow related to each other and thus can be called a collection.

Collections is merely an utility method class for doing certain operations, for example adding thread safety to your ArrayList instance by doing this:

List<MyObj> list = Collections.synchronizedList(new Arraylist<MyObj>());

The main difference in my opinion is that Collection is base interface which you may use in your code as a type for object (although I wouldn't directly recommend that) while Collections just provides useful operations for handling the collections.

Solution 5 - Java

Collection is an interface containing List, Set and Queue.

Collections is a class containing useful methods like Collections.sort() and Collections.synchronizedlist(), etc.

Solution 6 - Java

Collection is an root interface of Java collection framework. Collections is a utility class which contains static methods. example Collections.sort()

Solution 7 - Java

Collection, as its javadoc says is "The root interface in the collection hierarchy." This means that every single class implementing Collection in any form is part of the Java Collections Framework.

The Collections Framework is Java's native implementation of data structure classes (with implementation specific properties) which represent a group of objects which are somehow related to each other and thus can be called a collection.

Collections is merely an utility method class for doing certain operations, for example adding thread safety to your ArrayList instance by doing this:

List list = Collections.synchronizedList(new Arraylist());

The main difference in my opinion is that Collection is base interface which you may use in your code as a type for object (although I wouldn't directly recommend that) while Collections just provides useful operations for handling the collections.

Solution 8 - Java

Collection is an Interface which can used to Represent a Group of Individual object as a single Entity.

Collections is an utility class to Define several Utility Methods for Collection object.

Solution 9 - Java

Collection is a interface which is used to represent group of individual object as a single entity.

Collections is an utility class present in java.util. package to define several utility method (like sorting,searching ) for collection object.

Solution 10 - Java

Collection is a base interface for most collection classes (it is the root interface of java collection framework) Collections is a utility class

Collections class is a utility class having static methods It implements Polymorphic algorithms which operate on collections.

Solution 11 - Java

The Collections class is a utility class having static methods for doing operations on objects of classes which implement the Collection interface. For example, Collections has methods for finding the max element in a Collection.

Solution 12 - Java

Collection is an interface from which other class forms like List, Set are derived. Collections (with "S") is a utility class having static methods to simplify work on collection. Ex : Collections.sort()

Solution 13 - Java

As per Java Doc Collection is:

The root interface in the collection hierarchy. A collection represents a group of objects, known as its elements. Some collections allow duplicate elements and others do not. Some are ordered and others unordered. The JDK does not provide any direct implementations of this interface: it provides implementations of more specific subinterfaces like Set and List. This interface is typically used to pass collections around and manipulate them where maximum generality is desired.

Where as Collections is:

This class consists exclusively of static methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, "wrappers", which return a new collection backed by a specified collection, and a few other odds and ends.

Solution 14 - Java

Collections is a class which has some static methods and that method returns the collection. Collection is an interface,rather than root interface in collection hierarchy.

Solution 15 - Java

Yes, Collections is a utilty class providing many static methods for operations like sorting... whereas Collection in a top level interface.

Solution 16 - Java

Collection is a interface and Collections is class in Java.util package

Solution 17 - Java

Collections is a utility class, meaning that it defines a set of methods that perform common, often re-used functions, such as sorting a list, rotating a list, finding the minimum value etc. And these common methods are defined under static scope.

Collection is an interface that is implemented by AbstractCollection which in turn is implemented by AbstractList, AbstractSet etc.

Also, Collections class has thirty-two convenience implementations of its collection interfaces, providing unmodifiable collections, synchronized collections. Nearly all of these implementations are exported via static factory methods in one noninstantiable class (java.util.Collections).

Reference: Effective Java

Solution 18 - Java

collection is an interface and it is a root interface for all classes and interfaces like set,list and map.........and all the interfaces can implement collection interface.

Collections is a class that can also implements collection interface.......

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNirmalView Question on Stackoverflow
Solution 1 - JavaMirek PlutaView Answer on Stackoverflow
Solution 2 - JavauckelmanView Answer on Stackoverflow
Solution 3 - JavajaiView Answer on Stackoverflow
Solution 4 - JavaEskoView Answer on Stackoverflow
Solution 5 - JavaAnkitha sridharView Answer on Stackoverflow
Solution 6 - JavaAbhilashView Answer on Stackoverflow
Solution 7 - JavaSrinivasView Answer on Stackoverflow
Solution 8 - JavasrikanthView Answer on Stackoverflow
Solution 9 - JavaSitanshu ShuklaView Answer on Stackoverflow
Solution 10 - JavaMithilesh Kumar ThakurView Answer on Stackoverflow
Solution 11 - JavakevendraView Answer on Stackoverflow
Solution 12 - Javauser2450176View Answer on Stackoverflow
Solution 13 - JavaAnkush soniView Answer on Stackoverflow
Solution 14 - Javatitas royView Answer on Stackoverflow
Solution 15 - JavaShailendra SinghView Answer on Stackoverflow
Solution 16 - JavaRamnathView Answer on Stackoverflow
Solution 17 - JavaFatherMathewView Answer on Stackoverflow
Solution 18 - JavarajuView Answer on Stackoverflow