Reputation: 83
I am new to java development, I have bit doubt on how to slow down the for loop. I have set of list counts, and i iterate those using for loop. i want to iterate the count for certain time limit. (ie) the iterating time between count 1 and two should be delayed for 2 sec. is this possible to do. Pl guide me on this
Upvotes: 0
Views: 127
Reputation: 1478
Try using:
Thread.sleep(time); //time in milliseconds, in your case it is 2000
Upvotes: 1
Reputation: 2102
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
try {
System.out.println(i);
Thread.sleep(2000);
} //System.out.println(stem[0]);
catch (InterruptedException ex) {
Logger.getLogger(JavaApplication2.class.getName()).log(Level.SEVERE, null, ex);
}
}
Upvotes: 6
Reputation: 234685
The clearest way I can think of is to use
java.util.concurrent.TimeUnit.SECONDS.sleep(2);
Upvotes: 4