Soumak De has Published 84 Articles

How to implement Builder pattern in Kotlin?

Soumak De

Soumak De

Updated on 23-Nov-2021 06:17:19

725 Views

In object-oriented programming, the creation of objects is very easy via constructors when the object definitions are simple, but sometimes, it may so happen that the constructors need more variables or functions in order to initialize an object. In such cases, the "builder pattern" comes into picture which helps programmers ... Read More

How to convert a Kotlin source file to a Java source file?

Soumak De

Soumak De

Updated on 23-Nov-2021 06:13:27

585 Views

Kotlin is a statistically typed language that runs on JVM. Once a Kotlin file is compiled, it creates a .class file that can be executed on the JVM. In this article, we will see how we can convert a Kotlin source file to a Java source file. In this process, ... Read More

How to convert String to Long in Kotlin?

Soumak De

Soumak De

Updated on 23-Nov-2021 05:24:42

2K+ Views

In this article, we will see how to convert a String to Long in Kotlin using a library function. There are multiple ways to do it. Let's take a couple of examples to demonstrate how it's done.Example - using toLong()toLong() is a function that provides the most convenient way to ... Read More

Convert Kotlin Array to Java varargs

Soumak De

Soumak De

Updated on 23-Nov-2021 05:16:41

206 Views

Varargs, also known as "variable arguments" is a new mechanism in Java by which methods in Java can accept zero or multiple number of arguments. Before this mechanism, the only option available to achieve this type of functionality was "method overloading", but that also required multiple lines of boilerplate code.In ... Read More

Accessing Kotlin extension functions from Java

Soumak De

Soumak De

Updated on 23-Nov-2021 05:13:55

1K+ Views

In Kotlin, you can easily call another function by just importing the same in the current Kotlin file where your main function is running. Whatever the function we are declaring in a Kotlin file will be compiled into a static method by default, and it will be placed under the ... Read More

How to convert a List to a Map in Kotlin?

Soumak De

Soumak De

Updated on 27-Oct-2021 11:31:57

4K+ Views

In this article, we will see how we can convert a List to a Map using various options provided by the Kotlin Library.Example: Using associate()The most standard way of converting a list into a map is by using the associate() function. This function takes a list of items as an ... Read More

How to call a function after a delay in Kotlin?

Soumak De

Soumak De

Updated on 27-Oct-2021 11:21:22

3K+ Views

Kotlin is based on Java, hence we can use Java-based library functions to delay a function call. In this article, we will be using a Java library function to delay the function call using Timer() and schedule().Exampleimport java.util.Timer import kotlin.concurrent.schedule fun main(args: Array) {    // Execution starting ... Read More

What's the Kotlin equivalent of Java's String[]?

Soumak De

Soumak De

Updated on 27-Oct-2021 11:14:17

228 Views

String is a collection which is implemented using String class. As per the Kotlin documentation, a string can be defined as follows −Class String : Comparable, CharSequenceIn Kotlin, a string is a collection of characters. Strings are immutable in nature which means they are read-only. The length and elements of ... Read More

How can I get a random number in Kotlin?

Soumak De

Soumak De

Updated on 27-Oct-2021 11:10:06

12K+ Views

Kotlin provides multiple ways to generate a random number. In this article, we will see different ways to generate a random number and access it throughout the program.Example – Using Random classRandom() is an abstract class which generates random numbers with the given conditions. It can be accessed after importing ... Read More

How to get the current index of an array while using forEach loop in Kotlin?

Soumak De

Soumak De

Updated on 27-Oct-2021 11:05:59

4K+ Views

Sometimes it becomes necessary to access the index of an array. In this article, we will see how we can access the index of an array in Kotlin while using forEach loop.Example: Using forEachIndexed()nstead of using forEach() loop, you can use the forEachIndexed() loop in Kotlin. forEachIndexed is an inline ... Read More

Advertisements