Member-only story

Java ☕️ Maps 🗺 on the Kotlin.

Chetan Gupta
8 min readOct 31, 2020

Curious how Kotlin resolve the Java platform’s map?

Most of the Kotlin developers are migrated from the Java environment, they are pretty well versed with uses-cases and application of Collection Framework in the Java platform, but applying the same knowledge in a Kotlin codebase isn’t guaranteed to work always. You could end up with a spaghetti codebase base having a long trailing function and making hacks to achieve a functionality that could easily be solved using Kotlin’s standard functions easily. Kotlin stdlib which offers generic interfaces, classes, and functions for creating, populating, and managing Collections of any type.

In Today’s article, we will try to understand how Kotlin catered to Java Maps in his its colors. Disclaimer This article is specific to Kotlin JVM as collection implementation varies with the platform you are targeting in Kotlin. I’m Chetan Gupta, I do tech stuff, don’t forget to checkout from personal blogs from AndroidBites, without any delays, Let’s get started.

Note:
This Post is given `Silver award` in Reddit at r/android_devs,
thanks community for supporting my blogs and it really motivating me!

Map 🗺

It’s a collection of key-value pairs, mainly focus on retrieving a value against the key.

  • Keys are unique and similar to the index of an array.
  • A map can hold only one value against a key.
  • The map is a read-only collection but for the sake of understanding, I will be addressing it as Immutable*.
  • The modifying part is supported using Mutable maps, discussed later in the article.
  • Map<K, V> is not an inheritor of the Collection Interface, but it’s the part of the Kotlin Collection type.

Entries 🚪

An entry represents a key/value pair in a map.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Chetan Gupta
Chetan Gupta

Written by Chetan Gupta

Android & Kotlin Expert | Training & Technical writing for Bussiness contact https://t.me/ch810

No responses yet

Write a response