Soumya Kanti Naskar
Soumya Kanti Naskar

Reputation: 1081

TimeStamp While Printing

I have a scenario where there is an Arraylist of Strings (Basically English Quotes). I have generated a random no form '0' to 'ArrayList.size() - 1' and printed the String associated with the index. Is there any provision to keep a time stamp while printing that particular String so that it will not repeat the same string within next 10 minutes or any particular time span ? I have a infinite loop while printing and a delay of 10 sec after each iteration.

Upvotes: 0

Views: 74

Answers (1)

element11
element11

Reputation: 4475

You could create a simple Quote class that has a string and a java.util.Date object, and store an array of your Quote objects instead of just storing an array of strings.

Also, you could just store an array of Date objects of the same size as your string array, and use the same index from your string array to check the Date.

Whenever you print a quote, update the last used date in the class or Date array. When you go to print a new quote, check the last time it was printed.

Check out the java.util.Date docs for more details

Upvotes: 1

Related Questions