Practical solutions

Kotlin Howtos How-To Guides

Solve the problem. Keep building. Collection of Kotlin how-to articles

Find the answer you need

Browse practical solutions, grouped by the task you're working on.

__COUNT__ entries on this page

Difference Between CoroutineScope and coroutineScope in KotlinThis tutorial teaches the reader how CoroutineScope and coroutineScope work in Kotlin and what differentiates the two coroutine creators. How to Add Items to Mutable and Immutable ArrayList in KotlinThis article is about adding items to a mutable and immutable ArrayList in Kotlin. You will learn about different ways to do that. When and Where to Use the Kotlin Companion ObjectKotlin companion object is equivalent to Java's static instance. This article teaches how to use the companion object in Kotlin to take the object-oriented programming approach. How to Implement a Switch Case Statement in KotlinThis article teaches how to write a Java-like switch-case statement in Kotlin. It will also show different ways in which we can use the Kotlin switch-case statement. How to Initialize Array in Kotlin With ValuesThis article introduces the concept of how to initialize an array in Kotlin with values. We will be looking at different ways to initialize an array. How to Format String in KotlinThis article shows two ways to format string in Kotlin namely, string templates i.e using $ (dollar) sign and using String.format() method. How to Use the by Keyword in KotlinThe Kotlin by keyword is a new keyword introduced for delegation purposes. This article introduces the by keyword and its use in Kotlin. How to Initialize Properties Using by Lazy and Lateinit in KotlinKotlin allows property initialization with by lazy and lateinit keywords. This article sheds light on what they mean and how to use them in Kotlin. How to Concatenate Strings in KotlinTo concatenate two or more than two strings in Kotlin, we can use + (plus) operator, plus() method, String Builder, and String Templates. How to Convert a Java File Code to KotlinKotlin is now an official Android language. Hence, you might want to change your Java file to Kotlin. This article teaches you how to convert Java to Kotlin. How to Add Items to a List in KotlinThis article introduces different ways to add items to an existing list. We will go through each way to learn about adding a single item or an entire collection to a Kotlin list. How to Use of the Secondary Constructors in KotlinThis article introduces the concept of secondary constructors in Kotlin and how you can use it to initialize objects. How to Get the Current Index of a forEach Loop in KotlinKnowing the current index of a loop allows us to perform various actions on a particular item of a collection. This article teaches you how to get the current index of a forEach loop in Kotlin. How to Use setOnClickListener in KotlinThis tutorial shows the reader how to use the setOnClickListener method to invoke an event in a Kotlin application. How to Differentiate the Extension Functions in KotlinThis tutorial explains the extension functions in Kotlin in detail, gives an example for each function, and explains how they vary. How to Create an Empty Mutable List in KotlinThis tutorial teaches the reader the different ways that they can use to create an empty mutable list in Kotlin. How to Create and Execute Coroutines in KotlinThis tutorial introduces the reader to coroutines and shows how they can be executed sequentially or concurrently using async- await() in Kotlin. How to Parse JSON String to Object in KotlinThis tutorial teaches the reader the different ways they can use to parse a JSON object to an object in Kotlin. How to Get the Instance of an Object in KotlinThis tutorial teaches the reader how to get the instance of an object at runtime using Kotlin. How to Create Constants in KotlinThis tutorial teaches the reader how to create constants, the naming convention used in constants, and how to include them in the application. How to Use the reified Keyword in KotlinThis tutorial teaches the reader how to use the reified keyword in Kotlin to access type information. How to Get a Random Number in KotlinThis tutorial teaches the reader the different ways they can use to generate a random number in Kotlin. How to Convert List to Map in KotlinThis tutorial teaches the reader the different ways that they can use to convert a List to a Map data structure in Kotlin. How to Implicitly Infer the Type of Fail Method in JUnit 5This tutorial teaches the reader how they can implicitly infer the type of the fail method in JUnit 5.