+ 1

How to set an interval in Java (like you can do in JavaScript) (pls show example I still don't know)

Hello again. I would like to make a program that runs after a certain amount of time, but I have not been able to find the syntax for it on YouTube, here or on my java learning apps. How do I do this? (I want to have an interval in the way that Javasceipt set interval works but in Java) https://code.sololearn.com/ctZ01GndtgB3/?ref=app

13th Nov 2020, 2:45 AM
Cam UOR
Cam UOR - avatar
3 Answers
+ 6
Cam UOR hi again, if you are looking for solution (for Android), than postdelayed will be easier one, otherwise you can go with timer class. - both of this code will recall the task inside the run() method, for every 3 seconds. : Android postDelayed Method new Handler().postDelayed( new Runnable() { public void run() { //Run your task here } }, 1000 * 3); : Java timer class Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { //Run your task here } }; timer.schedule(task, 0L, 1000L * 3L);
13th Nov 2020, 1:28 PM
0_O-[MĂ€gĂĄr_SĂĄm_ÄkĂ _NĂŒllpÞïntĂȘr_ÈxĂ«cĂ©ptïön]~~
0_O-[MĂ€gĂĄr_SĂĄm_ÄkĂ _NĂŒllpÞïntĂȘr_ÈxĂ«cĂ©ptïön]~~ - avatar
0
Sorry I can't look at links cuz reasons
13th Nov 2020, 3:38 AM
Cam UOR
Cam UOR - avatar
0
I added some code showing what I have but it no work...
13th Nov 2020, 3:52 AM
Cam UOR
Cam UOR - avatar