title: ArrayList IndexOutOBoundsException after removing an object from ArrayList
body: <p>I am trying to find the anagrams of a word in a given input sentence. This is the exception I got when running the program.Is it due to the change in size of the list? Please help me getting out of the problem.</p>
  
  <pre><code>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 66, Size: 66
      at java.util.ArrayList.rangeCheck(Unknown Source)
      at java.util.ArrayList.get(Unknown Source)
      at MyClass.main(MyClass.java:28)
  </code></pre>
  
  <p>Here is my source code</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  import java.util.Scanner;
  
  public class MyClass {
  
      public static void main(String[] args) {
  
          Scanner sc = new Scanner(System.in);
          String wordin = sc.nextLine().toLowerCase();
          sc.close();
          List&lt;String&gt; word = new ArrayList&lt;String&gt;(Arrays.asList(wordin.split("\\s+"))); // splits the whole string into array of words
          ArrayList&lt;String&gt; sorted = new ArrayList&lt;String&gt;();
          int i,j;
          for (i = 0; i &lt; word.size(); i++) { // loop to sort letters of a particular word
              word.set(i, word.get(i).replaceAll("[^\\w]", ""));
              char[] ar = word.get(i).toCharArray();
              Arrays.sort(ar);
              sorted.add(String.valueOf(ar)); // add the sorted word to list
          }
  
          for(i=0;i&lt;sorted.size();i++){
              for(j=i;j&lt;sorted.size();j++){
                  char[] ar = word.get(j).toCharArray();
                  Arrays.sort(ar);
                  String current = String.valueOf(ar);
                  if(current.equals(sorted.get(i))){
                      System.out.println(word.get(j));
                                      word.remove(j);
                  }   
  
              }
  
  
          }
  
      }
  
  }
  </code></pre>