I have the following list of Integers

(0,1,2,3)

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:

(0,1),(1,2),(2,3),(3,0),(0,1)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.