Collection:-
A collection (sometimes called a container) is simply an
object that groups multiple elements into single unit. Collections are used to
store, retrieve, manipulate, and communicate aggregate data. Typically, they
represent data items that form a natural group, such as a poker hand (a
collection of cards), a mail folder (a collection of letters), or a telephone
directory (a mapping of names to phone numbers).
What is a Collections Framework?
- A collections framework is a unified architecture for representing and manipulating collections.
All collections frameworks contain the following-
- Interfaces: These are abstract data types that represent collections. Interfaces allow collections to be manipulated independently of the details of their representation.
- Implementations: These are the concrete implementations of the collection interfaces. In essence, they are reusable data structures.
- Algorithms: These are the methods that perform useful computations, such as searching and sorting, on objects that implement collection interfaces. The algorithms are said to be polymorphic: that is, the same method can be used on many different implementations of the appropriate collection interface. In essence, algorithms are reusable functionality.
Benefits of Collections Framework:-
- Reusability: Java Collections Framework provides common classes and utility methods than can be used with different types of collections. This promotes the reusability of the code. A developer does not have to re-invent the wheel by writing the same method again.
- Quality: Using Java Collection Framework improves the program quality, since the code is already tested and used by thousands of developers.
- Speed: Most of programmers report that their development speed increased since they can focus on core logic and use the generic collections provided by Java framework.
- Maintenance: Since most of the Java Collections framework code is open source and API documents is widely available, it is easy to maintain the code written with the help of Java Collections framework. One developer can easily pick the code of previous developer.
Difference between Collection and Collections :-
- Collection is an interface which can be used to represent a group of individual objects as single entity.
- Collections is an utility class present in java.util.package to define several utility methods (like sorting, searching) on collection objects.
No comments:
Post a Comment