title: How can I count and print duplicate strings in a string array in Java?
body: <p>I have a dilemma on my hands. After much trial and error, I still could not figure out this simple task.</p>
  
  <p>I have one array </p>
  
  <pre><code>String [] array = {anps, anps, anps, bbo, ehllo};
  </code></pre>
  
  <p>I need to be able to go through the array and find duplicates and print them on the same line. Words with no duplicates should be displayed alone</p>
  
  <p>The output needs to be like this</p>
  
  <pre><code>anps anps anps
  bbo
  ehllo
  </code></pre>
  
  <p>I have tried while, for loops but the logic seems impossible.</p>