title: Cut duplicate words from text
body: <p>I have text with following strings:</p>
  
  <pre><code>{whatever}:::duplicateString:::{whatever}
  {whatever}:::duplicateString:::{whatever}
  ....
  {whatever}:::duplicateString:::{whatever}
  {whatever}:::duplicateString:::{whatever}
  </code></pre>
  
  <p>How to remove <strong>duplicateString</strong> from text: the main idea is remove second word from line if it occurs more then one times.</p>
  
  <p>First idea was to read them line-by-line and split by "<strong>:::</strong>" in order to create arrays and iterate over arrays with adding entries to TreeSet. Good. But how then to glue up lines again?</p>
  
  <p>I can't to remember any mechanism to figure out such task.. Language doesn't matter, just approx solution?</p>
  
  <p>Example text:</p>
  
  <pre><code>Appliances:::Main
  Appliances:::Main:::Appliance Warranties
  Appliances:::Main:::Beer Keg Refrigerators
  Appliances:::Main:::Beverage Refrigerators
  Appliances:::Main:::Ceiling Fans &amp; Accessories
  Appliances:::Main:::Ceiling Fans &amp; Accessories:::Accessories
  Appliances:::Main:::Ceiling Fans &amp; Accessories:::Accessories:::Downrod Couplers
  Appliances:::Main:::Ceiling Fans &amp; Accessories:::Accessories:::Downrods
  Appliances:::Main:::Ceiling Fans &amp; Accessories:::Accessories:::Fan Replacement Blades
  </code></pre>
  
  <p>ideally it must be like:</p>
  
  <pre><code>Appliances:::Main
  Appliances:::Appliance Warranties
  Appliances:::Beer Keg Refrigerators
  Appliances:::Beverage Refrigerators
  Appliances:::Ceiling Fans &amp; Accessories
  Appliances:::Ceiling Fans &amp; Accessories:::Accessories
  Appliances:::Ceiling Fans &amp; Accessories:::Accessories:::Downrod Couplers
  Appliances:::Ceiling Fans &amp; Accessories:::Accessories:::Downrods
  Appliances:::Ceiling Fans &amp; Accessories:::Accessories:::Fan Replacement Blades
  </code></pre>