-6

difference between "collection" ,"Collection" and "Collections"

In the java.util package we going to use these three keywords so what is the difference between these keywords. 1) collection 2) Collection 3) Collections.

collection: It is word represent the Collection Object and Map object.

Collection: It is the super Interface of all Collection i.e. in The Array Format.

Collections: It is class , that contain the Utility methods to operate Collection Object.

Ankur Lathi
  • 7,636
  • 5
  • 37
  • 49
Mohsin Shaikh
  • 494
  • 1
  • 4
  • 11

7 Answers7

9

The Java collections framework (JCF) is a set of classes and interfaces that implement commonly reusable collection data structures.

Collection is an interface .

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.

Collections is a utility class , which has specific methods to work with collections.

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.

Read Oracle Java Collections tutorial

"collection" is a term to denote a container for elements. It is not a keyword or any class/interface name in Java. It can be used as an identifier to refer to a Collection. Probably you must have seen this :

Collection<String> collection ;

A collection — sometimes called a container — is simply an object that groups multiple elements into a single unit. Collections are used to store, retrieve, manipulate, and communicate aggregate data. Typically, they represent data items that form a natural group.

AllTooSir
  • 48,828
  • 16
  • 130
  • 164
5
  • collection: does not mean anything special. It can be a variable name you use to refer to a Collection

  • Collection: an interface that (most) collections implement - see javadoc

  • Collections: a set of utility methods - see javadoc
Steve P.
  • 14,489
  • 8
  • 42
  • 72
assylias
  • 321,522
  • 82
  • 660
  • 783
1

Please read up on the Java API:

  • Collection: 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.

  • Collections: 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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Filip
  • 857
  • 8
  • 19
1

Neither of these are Java language keywords.

collection is most likely an identifier, a variable name perhaps ? As the first letter is small case.

Collection is an interface, declaring the behavior of all the collection implementations: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Collection.html

Collections is a utility class with a set of static methods, which help with manipulation of Collection objects: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Collections.html

S.D.
  • 29,290
  • 3
  • 79
  • 130
1

collection: It is simply a english word. You can use it to create any java object/instance variable

Collection: Root interface of the collection framework. All the interface those are part of Collection Framework internally extends this interface.

Collections: It is a utility class in java which extends Object class.

Krishna Kumar Chourasiya
  • 2,030
  • 3
  • 20
  • 23
0

Collection is an interface for various interfaces/classes for collections of elements, like List, ArrayList, Set and HashSet.

Collections is a utilityclass containing methods that can be used on classes that implement the Collectioninterface.

collection is just a variable name I think.

Tobb
  • 11,850
  • 6
  • 52
  • 77
  • what about the collection word. – Mohsin Shaikh Aug 01 '13 at 08:16
  • `Collection` and `Collections` are both files that are part of the java.util package. I can't find any file names `collection`, so not sure what you're asking really.. As per the Java naming convention, `collection` is most likely just a variable name.. – Tobb Aug 01 '13 at 08:34
  • In some docs they define collection is represent a structure. – Lawakush Kurmi Feb 10 '16 at 18:51
0

java.util.Collection: The root interface in the collection hierarchy
java.util.Collections: utility class
collection: I don't known

Read Oracle doc about collection

Luca Basso Ricci
  • 17,829
  • 2
  • 47
  • 69