Checking for two consecutive elements in Collection
Greetings knowledgeable Java people.
I've hit a wall again, and I'm afraid I'll sink deeper into your debts. :(doh):
please consider with me, the following collection. Let's say it is of type ArrayList (I don't think it matters too much what type of collection it is).
What would be the best approach to take if I wanted to check the ArrayList and see if the two numbers  and  ever come neighbours of each other ? and if they do, add the couple into the ArrayList once more (right after their original index), making the final list as follows:
[1 , 2 , 4 , 8 , 4 , 8 , 16]
I've thought hard about it, but my programming logic is still minute compared to yours. And couldn't really come up with anything of use.
I would greatly appreciate any help.