title: Concatenating elements of ArrayList while iterating
body: <p>I am interested in concatenating a string to elements of an arraylist while iterating.When I run the below code,I am getting a ConcurrentModificationException.My code is:</p>
  
  <pre><code>ArrayList&lt;String&gt; list=new ArrayList&lt;String&gt;();
  list.add("000);
  list.add("00");
  list.add("0");
  for(String s:list)
  {
      if(s.length()==1)
      {
          String s2="000" + s;
          list.add(s2);
  
      }
  
  
      if(s.length()==2)
      {
          String s2="00" + s;
  
      }
  
  
      if(s.length()==3)
      {
          String s2="0" + s;
      }
  }
  </code></pre>
  
  <p>My question is how to add the concatenated strings back to list without using StringBuilder as when I use a StringBuilder,it is causing other parts of my program to malfunction? So just need some guidance.</p>