Java Comparing Words
<p>I had a problem with <code>array out of bounds</code> before on this, but I don't receive that anymore. </p>

<p>My problem is when using my <code>ArrayList</code>, it will print out:</p>

<pre><code>aba, aba, abaa, abaxxa, runner, runner, runners, school, school, schooling, schools, tasker, tasker
</code></pre>

<p>Leaving out <code>task</code>, and <code>run</code>. </p>

<p>I have been looking at this for a while and i can't figure it out. Any help would be great!</p>

<pre><code>import java.io.*;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;


public class RootWords {

    public static void main(String[] args) {
        String Word;

        List&lt;String&gt; xList = new ArrayList&lt;String&gt;();
    try{
        BufferedReader reader = new BufferedReader(new FileReader("Words.txt"));
        while ((Word = reader.readLine()) != null) {
        xList.add(Word);
        }
        }
    catch (IOException ioe){
        System.out.println("Problem opening input file");
        }


        String[] Words = new String[ xList.size() ];

        Collections.sort(xList);
        xList.toArray( Words );

        int c;
        String roots = "";

        for( int i = 0; i &lt; Words.length ; i++ ){
                c = root(Words[i],Words[i+1]);

        if(c &gt;= 3 || c &lt;=5 ){
            roots = Words[i];
            System.out.printf("%s\n", roots);

        while(Words[i].startsWith(roots)){
            System.out.printf("%s\n", Words[i]);
            i++;
        }
    //  i--;
        }
        }
        }
public static int root(String a, String b){
        int min;

        if(a.length() &lt; b.length() ){
                min= a.length();
        }
        else{
            min = b.length();
        }
        //return min;

        int i;

        i = 0;
        while (i &lt; min)
        {
            if (a.charAt(i) == b.charAt(i))
            i++;
        else break;

    }  

    return i;
    }
}
</code></pre>

<p>I don't receive the array out of bounds with the code I have, I am having trouble having the full list print out. I get a while with aba run school task abaa tasker tasking abaxaa runner running runners schools schooling but then when I print it out aba aba abaa abaxaa runner runner runners school school schooling schools tasker tasker. Thus I am missing task and run</p>
