Soumak De has Published 84 Articles

Best way to null check in Kotlin

Soumak De

Soumak De

Updated on 04-Oct-2023 21:25:58

23K+ Views

In any programming paradigm, it is mandatory to check "null safety" in order to prevent runtime errors. In this article, we will see different ways to check "null safety" in Kotlin. Example - Using if…else In most of the programming languages, we have the "if" keyword to ... Read More

How to find the number of repeated values in a Kotlin list?

Soumak De

Soumak De

Updated on 16-Mar-2022 14:35:30

3K+ Views

In this article, we will see how to find the number of repeated values in a Kotlin list.Example – Finding Repeated Values Using groupingBy()The Kotlin library provides an inline function called groupingBy() which creates a grouping source from an array to be used later with one of the group-and-fold operations ... Read More

How to create a mutable list with repeating elements in Kotlin?

Soumak De

Soumak De

Updated on 16-Mar-2022 14:31:20

1K+ Views

A Mutable List is an interface and generic collection of elements. Once a collection is declared as mutable, it becomes dynamic and we can modify its data as per requirement. A mutable list grows automatically in size as we insert new elements into it. The Mutable List inherits form the ... Read More

@Throws Annotation in Kotlin

Soumak De

Soumak De

Updated on 16-Mar-2022 14:24:34

2K+ Views

The concept of exception in Kotlin is very much same as it is in Java. All the exceptions in Kotlin are the descendants of the Throwable class. @Throws annotation indicates what exceptions should be declared by a function when compiled to a JVM method.Example – Throwing exception using a methodIn ... Read More

How to initialize List in Kotlin?

Soumak De

Soumak De

Updated on 16-Mar-2022 14:16:24

616 Views

List denotes a List collection of generic data type. By , we understand that the List does not have any specific data type. Let's check how we can initialize such a collection in Kotlin.List can be of two types: immutable and mutable. We will see two different implementations of initializing ... Read More

How to work with Maps in Kotlin?

Soumak De

Soumak De

Updated on 16-Mar-2022 14:07:44

196 Views

A Map is a collection where data is stored as a key-value pair and the corresponding keys have to be unique. A HashMap is a collection class based on MutableMap interface and it does that by implementing the MutableMap interface of HashTable.Kotlin provides four types of constructors to define and ... Read More

How to replace duplicate whitespaces in a String in Kotlin?

Soumak De

Soumak De

Updated on 16-Mar-2022 13:47:34

3K+ Views

In order to remove extra whitespaces in a string, we will use the replace() function along with toRegex() function from the String class. To replace all the consecutive whitespaces with a single space " ", use the replace() function with the regular expression "\s+" which matches with one or more ... Read More

How to use Java's bitwise operators in Kotlin?

Soumak De

Soumak De

Updated on 16-Mar-2022 13:43:09

446 Views

Kotlin provides a set of bitwise operators that we can use on integers. These operators can be applied only to Int and Long type variables. Here is the list of bitwise operations available in Kotlin −shl(bits) – Signed Shift leftshr(bits) – Signed shift rightushr(bits) – Unsigned shift rightand(bits) – Bitwise ... Read More

What does "return@" mean in Kotlin?

Soumak De

Soumak De

Updated on 16-Mar-2022 13:38:40

3K+ Views

return@ is a statement in Kotlin which helps the developers to return a function to the called function. In simple words, return@ can return any value, anonymous function, simple inline function, or a lambda function.Example – return in Kotlinfun main(args: Array) {    val s = message()    println("Message = ... Read More

How to initialize an empty array list in Kotlin?

Soumak De

Soumak De

Updated on 16-Mar-2022 13:32:42

5K+ Views

Kotlin ArrayList class can be used in order to create an empty arrayList. It would be a dynamic array which means it will automatically expand as we add data into it. An ArrayList is an ordered sequence of elements, however, unlike simple arrays, an ArrayList can contain data of multiple ... Read More

1 2 3 4 5 ... 9 Next
Advertisements