I have the following list of Integers


Now I want to write a method which returns specific number of pairs from the list. So if I give it 5 as argument I will expect it to return the following:


So basically when it reaches the end element and another pair is needed, then it should pair the last element of the list with the first one and continue.

Any ideas how can I implement this?

Foreach element you take, you need to take the next element too. If the next element is bigger then your ArrayList Size you need to take first element again (reset to 0). To stop you can make an if statement to check if the counter reaches your argument of 5 or ...

I should use a For statement (like a counter). And a method where you pass your list and argument too.

Sorry for broken English.