title: Writing a method with ArrayList of strings as parameters
body: <p>I am trying to write a method that takes an ArrayList of Strings as a parameter and that places a string of four asterisks in front of every string of length 4.</p>
  
  <p>However, in my code, I am getting an error in the way I constructed my method. </p>
  
  <p>Here is my mark length class</p>
  
  <pre><code>import java.util.ArrayList;
  
  
  public class Marklength {
  
      void marklength4(ArrayList &lt;String&gt; themarklength){
          for(String n : themarklength){
              if(n.length() ==4){
                  themarklength.add("****");
              }
          }
          System.out.println(themarklength);
      }
  
  }
  </code></pre>
  
  <p>And the following is my main class: </p>
  
  <pre><code>import java.util.ArrayList;
  
  
  public class MarklengthTestDrive {
      public static void main(String[] args){
  
          ArrayList &lt;String&gt; words = new ArrayList&lt;String&gt;(); 
  
          words.add("Kane");
          words.add("Cane");
          words.add("Fame");
          words.add("Dame");
          words.add("Lame");  
          words.add("Same");
  
          Marklength ish = new Marklength();
  
          ish.marklength4(words);
  
      }
  }
  </code></pre>
  
  <p>Essentially in this case, it should run so it adds an arraylist with a string of <code>"****"</code> placed before every previous element of the array list because the lengths of the strings are all 4. </p>
  
  <p>BTW </p>
  
  <p><strong>This consists of adding another element</strong></p>
  
  <p>I am not sure where I went wrong. Possibly in my for loop?</p>
  
  <p>I got the following error: </p>
  
  <pre><code>Exception in thread "main" java.util.ConcurrentModificationException
      at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
      at java.util.AbstractList$Itr.next(AbstractList.java:343)
      at Marklength.marklength4(Marklength.java:7)
      at MarklengthTestDrive.main(MarklengthTestDrive.java:18)
  </code></pre>
  
  <p>Thank you very much. Help is appreciated. </p>