How to call a function after a delay in Kotlin?

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().


import java.util.Timer
import kotlin.concurrent.schedule

fun main(args: Array<String>) {

   // Execution starting point
   println("Hello world!!")

   // Delay of 5 sec

      //calling a function

fun newMethod(){
   println("Delayed method call!")


Once executed, the above piece of code will yield the following output −

Hello world!!
Delayed method call!

Updated on: 27-Oct-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started