Sleep Function Example Java Program


Sleep causes the current thread to suspend execution for a specified period. This is an efficient means of making processor time available to the other threads of an application or other applications that might be running on a computer system.



Sleep Function Example Program

public class SleepFunctionDemo {
    public static void main(String args[])
        throws InterruptedException {
        String[] str = {
            "This is statement 1",
            "This is statement 2",
            "This is statement 3",
            "This is statement 4"
        for (int i = 0;i < str.length;i++) {
			System.out.println("After 4 seconds....");


Sample Output

Output is:
This is statement 1
After 4 seconds....
This is statement 2
After 4 seconds....
This is statement 3
After 4 seconds....
This is statement 4
After 4 seconds....