kotlin

kotlin

How to check if a number is positive, negative or zero in Kotlin

In this Kotlin programming tutorial, we will learn how to check if a number is positive, negative or zero in Kotlin. We will implement this program with a when block.

Read
kotlin

How to convert a string to Date in Kotlin

Convert a string to a date in Kotlin with example. We will use java.util.LocalDate class to convert a string to a Date.

Read
kotlin

How to read user input in Kotlin

In this tutorial, we will learn how to take user input in Kotlin with different examples. Reading user input in Kotlin is easy. Kotlin provides one inbuilt function to make this task easy for us.readLine() function allow us to read the input that is entered by the user. This function actually read the input as a string. We can convert it to a different datatype if we want.Alternatively, we can also use Scanner class to read the content of user input.

Read
kotlin

Safe call operator in Kotlin with example

Safe call operator is denoted by ? in Kotlin. This operator is mainly used to remove null pointer exception or NPE in Kotlin. In this tutorial, we will learn how to use safe call operator in Kotlin with different use cases.In this tutorial, we will learn how to use safe call operator in Kotlin with different use cases.

Read
kotlin

Learn Named argument in Kotlin with examples

Named argument is used to improve the readability of a kotlin function. Named argument, as the name suggested is arguments with a name. For example, let's take a look at the below function :.

Read
kotlin

What is elvis operator in Kotlin

Elvis operator is used to removing null pointer exception in Kotlin. We can use it to check if any variable is null or not and it allows us to use one default value if the value is null.The syntax of elvis operator is ?.

Read
kotlin

What is double bang or double exclamation operator in kotlin

Double bang (!!) or double exclamation operator or not-null assertion operator is used with variables if you are sure that the value will be always non-null.If a value is null and if we are using not-null assertion operator, it will throw one null pointer exception.So, we should use this operator only if we want to throw one exception always if any null value found.

Read
kotlin

Learn default arguments in Kotlin functions with example

This post is about "default arguments" in kotlin and their use cases.

Read
kotlin

How to intersect two arrays in Kotlin

The intersection is used to find out the common elements in two arrays. For example, if array A holds 1,2,3,4,5 and array B holds 2,5,6, the intersection between A and B will be 2,5.In this tutorial, we will learn how to find out the intersection between two array elements.

Read
kotlin

5 different ways to sort a list in ascending/descending order in Kotlin

Learn to sort a list of items in Kotlin in both ascending and descending orders. We will also learn how to sort a list of objects with a comparator and with a selector.

Read