1Syntax :
2=========================================================
3 Thread.sleep(1000); // 1000 milliseconds.. |
4=========================================================
5int i=0;
6for(;;){
7 Thread.sleep(2000); // set time delay to 2 seconds..
8 System.out.println(i++); // output : every output will display after 2 seconds..
9}
1//deprecated in main thread:
2try {
3 Thread.sleep(1000);//time is in ms (1000 ms = 1 second)
4} catch (InterruptedException e) {e.printStackTrace();}
5
6//please use bellow instead:
7Timer timer = new Timer();
8timer.schedule(new TimerTask() {
9 @Override
10 public void run() {
11 //what you want to do
12 }
13}, 1000);//wait 1000ms before doing the action