title: Print words which occurs more than once from a string
body: <p>I am trying to find and print the words in a string that occurs more than one. And it works almost. I am however fighting with a small problem. The words a printed out twice since they occur twice in the sentence. I want them printed only once:</p>
  
  <p>This is my code:</p>
  
  <pre><code>public class Main {
  
  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
  
      String sentence = "is this a sentence or is this not ";
      String[] myStringArray = sentence.split(" "); //Split the sentence by space.
  
      int[] count = new int[myStringArray.length];
      for (int i = 0; i &lt; myStringArray.length; i++){
         for (int j = 0; j &lt; myStringArray.length; j++){
             if (myStringArray[i].matches(myStringArray[j]))
                 count[i]++;
             //else break;
         }
      }
      for (int i = 0; i &lt; myStringArray.length; i++) {
              if (count[i] &gt; 1)
            System.out.println("1b. - Tokens that occurs more than once: " + myStringArray[i] + "\n");
      }
  }
  </code></pre>
  
  <p>}</p>