What is Collections in Java………
Collections are an interface in the java.util package, and as its name suggests, it is used to define a collection of objects. There are many different classes which implement the collections interface. Each one has its unique features, some add elements in a sorted manner, others in a binary fashion. But there are two basic structures, a map and a list and most others extended these interfaces.
Collections are objects whose sole purpose is to store other objects, like arrays. Unlike arrays, however, collections have convenience methods to, say, return a portion of the original collection. A drawback of collections is that they can’t hold primitives. (They can, however, hold wrappers, like
All collection objects ultimately implement the
java.util.Collection interface. However, few if any implement the interface directly. There are multiple sub-interfaces of
Collection that specify additional methods. These sub-interfaces decide the functionality of a collection; individual classes usually differ only in implementation. (For example, both
LinkedList fulfill the general contract of the
List interface, but do so differently.)
Most implementations of the
Collection interface are in
java.util. Exceptions will be noted when introduced.
Map interface does not extend
Collection, it is usually included in discussions of collections and will be explained here.
Share the knowledge