Scrabble algorithm review and performance suggestions After finishing Project Euler 24, I decided to make a scrabble type of application using /usr/lib/dict as my dictionary what I cat that into a word file. It does take a few seconds, and the dictionary selection isn't that great.

Is there any way I could make it faster, more effective, and with a better dictionary source?

public class Scrabble {

    public static ArrayList&lt;String&gt; numbers = new ArrayList&lt;String&gt;();
    public static ArrayList&lt;String&gt; numbers2 = new ArrayList&lt;String&gt;() {
    };

    public static void main(String[] args) {
        Scanner dict = null;

        try {
            dict = new Scanner(new File("words.txt"));
        } catch (FileNotFoundException ex) {
        }

        while (dict.hasNextLine()) {

            numbers.add(dict.nextLine());
        }

        String n = "gojy";//random text here

        rearrange("", n);
        LinkedHashSet&lt;String&gt; listToSet = new LinkedHashSet&lt;String&gt;(numbers2);
        ArrayList&lt;String&gt; listWithoutDuplicates = new ArrayList&lt;String&gt;(listToSet);
        for (int i = 0; i &lt; listWithoutDuplicates.size(); i++) {

            if (numbers.contains(listWithoutDuplicates.get(i))) {
                System.out.println(listWithoutDuplicates.get(i));
            }
        }

    }

    public static void rearrange(
            String q, String w) {
        if (w.length() &lt;= 1) {
            String k = q + w;
            numbers2.add(k);//full word
            numbers2.add(q);//smaller combination to get words with less letters. doesn't work too well
        } else {

            for (int i = 0; i &lt; w.length(); i++) {

                String c = w.substring(0, i)
                        + w.substring(i + 1);

                rearrange(q
                        + w.charAt(i), c);

            }
        }
    }
}
If what you are trying to do is store a huge list of valid words in such a way that you can test whether a given string is a valid word, a Trie works well.  See this Stack Overflow question.

Load the wordlist into the Trie when your server starts, and use the same Trie for all games (assuming this is a client server game).  It's trickier than the linked thread if you need to include more than the standard 26 letters of the alphabet, but I've done a Unicode Trie for a chat filter before and I could help if you need that.

I don't understand what you are trying to do with the rearrange method.  Can you explain?