Alde
Alde

Reputation: 428

Loop through an array with delay in Java

This is my second post! Thanks again for the help on the previous thread.

Today I have a very stupid question that I couldnt find any great answer to on Stack or anywhere else. I'm sorry if this is a duplicated question.

I am looking for a way too loop trought an array, perform something and then wait a delay of 1 sec in Java.

Here is the array ;

String[] bros = {"LUMIDOS", "Papineau", "Tayeul"};

and here is where I want to perform an action for each members of that array.

        for(String s : bros){
            message = "/tell "+s.bros+" some random text here";
        }

Also I think that my iteration is wrong..

Upvotes: 0

Views: 1959

Answers (1)

Abimaran Kugathasan
Abimaran Kugathasan

Reputation: 32478

Make the current executing Thread to sleep for 1 sec after you perform the action. And, there was a small correction in accessing the element of the array.

for(String s : bros){
        message = "/tell " + s + " some random text here";
        Thread.sleep(1000);
}

Upvotes: 4

Related Questions