how to call a method after a time interval? e.g if want to print a statement on screen after 2 second, what is its procedure?
System.out.println(\"Printing s
Create a Class:
class SayHello extends TimerTask {
public void run() {
System.out.println("Printing statement after every 2 seconds");
}
}
Call the same from your main method:
public class sample {
public static void main(String[] args) {
Timer timer = new Timer();
timer.schedule(new SayHello(), 2000, 2000);
}
}