+ 1

Is it actually possible to delay actions in java ?

Can we delay actions in java, for exemple when we run the code : "a" Prints instanlly, then "b" Prints after 1000ms so we see "b" 1 second after "a" ?

29th Jan 2018, 10:02 PM
Clément LEGER
Clément LEGER - avatar
2 Respostas
+ 12
You can, but not on Code Playground, as it does not provide a live console.
29th Jan 2018, 10:05 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
Yes , it is possible to do such using Java. But I'm afraid you can't do it using the Code Playground environment provided here. However to implement such , you will use the Thread.sleep(1000) method . This will cause a delay of 1 sec. A snippet of this is given below: try{ System.out.println("a"); Thread.sleep(1000); System.out.println("b"); }catch(Exception e){ } I hope it helps.
29th Jan 2018, 11:01 PM
Babafemi Sorinolu
Babafemi Sorinolu - avatar