Add a delay : Sleep Pause « Thread « Java Tutorial





public class Main {
  public static void main(String[] args) {
    for (int i = 0; i < 10; i++) {
      System.out.println("i = " + i);

      try {
        Thread.sleep(1000);

      } catch (InterruptedException ie) {
        ie.printStackTrace();
      }
    }
  }
}










10.18.Sleep Pause
10.18.1.Pause the execution
10.18.2.Pausing the Current Thread: a thread can temporarily stop execution.
10.18.3.Add a delay
10.18.4.Pause the execution of a thread using sleep()