
How can we use sleep method in thread ?

public class test {
public static void main(String [] args){
String str[] ={"Delhi","Bihar","Goa"
,"Pune" ,"Mumbai"};
for (int i = 0; i <str.length; i++) {
try {
System.out.println(str[i]);
Thread.sleep(5000);
} catch (InterruptedException e) {
}
}
}
}
Output
Delhi Bihar Goa Pune mumbai
Description:- In this thread example ,we have used sleep method. we are passing some interval to the sleep method .After that interval thread will awake.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.