Pre-pending / Appending pairs of strings in a list
<p>I have a list of pairs of strings such as:</p>

<pre><code>A C
B D
B C
A D
</code></pre>

<p>I would like to loop through the list so that I will get a string as follows:</p>

<pre><code>A C B D A
</code></pre>

<p>Is such a thing possible and practical if I were to have n pairs?</p>

<p>UPDATE: My bad for not describing it clearly.
I have a:
List x = ....
x.add("AC");
x.add("BD");
x.add("BC");
x.add("AD");
...
...</p>

<p>I would like to loop through such that if the next row's starting item is the current row's ending item then I will discard both and insert a new item.  Vice versa if the next row's ending item is the current row's starting item.</p>

<p>e.g. </p>

<p>Current Item: AC
Next row's item: BD
</p>

<p>Current Item: AC
Next row's item: BC
New item: ACB</p>

<p>Update list will then have:</p>

<p>ACB
BD
AD</p>

<p>Then I will have to repeat the process until I get ACBDA.</p>

<p>Haha... talking about this already gave me an idea how to solve it.  Looks like it helps talking about it.</p>
