First of all, do not declare your variable as a LinkedList, declare its List (parts of the code that are not related to the remote list:
public class WordSearch { List<String> lxx; public WordSearch(String wordlist) throws IOException { lxx = new LinkedList<String>(); } }
Next, do not call get on the list, using LinkedList get will be VERY slow. Use an iterator instead ... better still use the new stype for the loop that the iterator uses for you:
public boolean inTheList (String theWord) { for(String word : lxx) { if (theWord.compareToIgnoreCase(word) == 0) { return true; } } return false; }
Then change the new LinkedList to the new ArrayList:
lxx = new ArrayList ();
This code should be faster, but you can still do better.
Since you don't need duplicate words, use Set instead of List and use HashSet instead of ArrayList.
This will greatly speed up the program.
Your source code, using LinkedList with get, should start at the top of the list every time you search for the next word in the list. Using Iterator (through a new style for each loop) stops this.
Using LinkedList means that every time you need to go to the next word in the list, there is a related search, ArrayList does not have this overhead.
The use of the HashSet is completed (possibly) using a tree structure that has a very fast search.
Tofubeer
source share