Reputation: 399
I am very new in Java. Say I have a ArrayList
with 10 string items, what I am trying to archive are
Print each items every second.
When all items are printed, it will return to the beginning, repeating printing
Can you give me some ideas in Java
ArrayList<String> testAL = new ArrayList<String>();
Timer tickerTimer = new Timer();
TimerTask sendMessageTask = new TimerTask() {
public void run() {
}
};
Upvotes: 0
Views: 156
Reputation: 437
You can try something like:
try {
for (int i = 0; i < testAL.size(); i++) {
System.out.println(testAL.get(i);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
And run your TimerTask
from the main... Also you got a Timer
that can execute the TimerTask
run every X seconds...
Upvotes: 1