The advantages of a collections framework

So, what is the benefit of having a collections framework? There are several benefits, but, most importantly, it reduces the programming time and effort. The collections framework provides a developer with high-quality (in terms of performance and code optimization) implementations of useful data structures and algorithms, while providing you with interoperability between unrelated APIs. You can use these implementations in your program, thus reducing your programming effort and time.

So, as we have got to know what the collections framework is, let us now have a look at the hierarchy of classes and interfaces in the collections framework.

So, let's go through the following figure:

As we mentioned earlier, the collections framework is a set of data types and classes that lets us work with a group (or groups) of data. That group may be in the form of a simple list/map/set or any other data structure.

The preceding figure represents the collections framework of Kotlin. Just like Java, all collection interfaces in Kotlin are originated from the Iterable interface. However, the Kotlin collections framework is a bit different than that of Java; Kotlin distinguishes between mutable and immutable collections.

Kotlin has two base collection interfaces, namely Iterable and MutableIterable. The Iterable interface is extended by the Collection interface, which defines basic read-only collection operations (like size, isEmpty(), contains(), and so on).

The MutableCollection interface extends the Collection interface and the MutableIterable interface, adding the read-write feature.

Before the collections framework was introduced in Java, developers used to use arrays, vectors, and HashTables to work with a group of data. The problem with this approach was that none of them have some common methods. The collections framework was thus created to make a developer's life easier by providing common methods and operations across various types of collections.

The collection framework was introduced in Java before formation of the Kotlin language and it has been included in Kotlin from the very beginning.

Aren't you curious about why there are so many collection types? Let's find out the purpose of some of the most commonly used collection types as we cover them in the following sections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.215.96