Home » JVM Languages » Kotlin

Kotlin

Kotlin – Convert List to Map Examples

1. Overview In this tutorial, We’ll learn how to convert the List to Map in Kotlin programming. Let us explore the different ways to do it. 1. Overview In this tutorial, We’ll learn how to convert the List to Map in Kotlin programming. Let us explore the different ways to do this conversion. Kotlin provides a set of methods for ...

Read More »

How To Convert String to Float in Kotlin?

1. Overview In this tutorial, We will learn how to convert the String value to Float in Kotlin. This conversion is done using toFloat() method of String class. But there are many cases where it gives parsing errors for wrong inputs. 2. Kotlin String to Float using toFloat() Method Converting string to float is done with toFloat() method of string ...

Read More »

Kotlin – Convert Map to List Examples

1. Overview In this tutorial, We will learn how to convert the Map to List in kotlin programming. Map implementations such as HashMap or TreeMap can be converted into an ArrayList or List object. Let us explore thedifferent ways to do this conversion. 2. Converting HashMap to List in Kotlin Using ArrayList Constructor This approach is the simple one and ...

Read More »

Kotlin: Multi variable null check

Although not-null, immutable variables with sensible defaults are often desired, it is not always the case. It is sometimes required to check if multiple variables are not null. This post describes several variants of how to do this when smart casts are not possible because the variables are mutable. Consider the following example: class Person() { var name: String? = ...

Read More »

Validation in Kotlin: Valiktor

Bean Validation is the Java standard for validation and can be used in Kotlin as well. However, there are also two popular alternative libraries for validation available in Kotlin: Konform and Valiktor. Both implement validation in a more kotlin-like way without annotations. In this post we will look at Valiktor. Getting started with Valiktor First we need to add the ...

Read More »

Getting started with Ktor

Ktor (pronounced kay-tor) is an open source Kotlin framework for building asynchronous web applications. This post shows how to create a small RESTful CRUD service with Ktor. Getting started In this example we use Maven as build tool. Besides standard Kotlin dependencies we need to add the Ktor dependencies to our pom.xml: 01 02 03 04 05 06 07 08 ...

Read More »

Kotlin / IntelliJ quick hint: Operator navigation

This is just a quick hint if you are programming Kotlin with IntelliJ: In IntelliJ you can ctrl-click on operators to navigate to the operator definition (similar to ctrl-clicking on methods). This also works for the get operator (you can click on the [] brackets) and for ranges (you can click on the dots (..) between the start and end ...

Read More »

Kotlin infix functions

What are infix functions? If you are using Kotlin chances are high you already used infix functions. Maybe without knowing it. When calling infix functions it is possible to omit the dot and the parentheses. So instead of 1 car.move(forward) we can write: 1 car move forward Here are a few examples of commonly used infix functions in Kotlin. The ...

Read More »