title: Printing an ArrayList while reading it for print conditions
body: <p>I have two <code>ArrayList&lt;String&gt;</code>s. One contains words with punctuation and capitalization, the other has these removed.</p>
  
  <p>List1:</p>
  
  <pre><code>File word: it's
  File word: Sit
  File word: yes-man
  File word: murdered
  File word: ok
  File word: DereDrum
  File word: Hello
  File word: Friend
  </code></pre>
  
  <p>List2:</p>
  
  <pre><code>Edited word: its
  Edited word: sit
  Edited word: yesman
  Edited word: murdered
  Edited word: ok
  Edited word: deredrum
  Edited word: hello
  Edited word: friend
  </code></pre>
  
  <p>The idea was to check and see which words are anagrams of each other. If they were, all I want to do is reprint them, but with the words that are anagrams on the same line as each other:</p>
  
  <pre><code>it's Sit
  
  yes-man
  
  murdered DereDrum
  
  ok
  
  hello
  
  friend
  </code></pre>
  
  <p>I tried to do this like so:</p>
  
  <pre><code>        for (int i = 0; i &lt; words.size(); i++)
          {
              System.out.print(words.get(i));
              for (int j = i+1; j &lt; grams.size(); j++)
              {
                  anagramChecker(grams.get(i),"",grams.get(j),words.get(j));
              }
              System.out.println();
          }
  </code></pre>
  
  <p>The way I had it in mind was that this for loop lasts for the size of the List1(words) and prints the word it's looking at. Then I use my anagramChecker:</p>
  
  <pre><code>public static void anagramChecker(String s1,String s2,String checked,String word)
  {
      if(s1.length() == 0)
      {
          if(s2.equals(checked))
          {
              System.out.println(" " + word);
              return;
          }
      }
      for(int i = 0 ; i &lt; s1.length() ; i++)
      {
          anagramChecker(s1.substring(0, i) + s1.substring(i+1, s1.length()),s2 + s1.charAt(i),checked,word);
      }
  }
  </code></pre>
  
  <p>This method did not work and it's output was something like this:</p>
  
  <pre><code>it's
  Sit yes-man
   yes-man
   yes-man
   yes-man
   yes-man
   yes-man
   yes-man
   yes-man
  
  yes-man
  murdered
  ok
  DereDrum Hello
  
  Hello
  Friend
  </code></pre>
  
  <p>I tried using a map so I could sort the words alphabetically after the words themselves were sorted alphabetically in the second list. That had about the same looking output.</p>