Mar*_*ska 8 java data-structures
我有这个代码,用于确定单词(忽略大小写)是否包含在wordList文本文件中.但是,wordList文本文件可能有65000 ++行,并且只使用我的实现在下面搜索单词需要将近一分钟.你能想到更好的实施吗?
谢谢!
import java.io.*;
import java.util.*;
public class WordSearch
{
LinkedList<String> lxx;
FileReader fxx;
BufferedReader bxx;
public WordSearch(String wordlist)
throws IOException
{
fxx = new FileReader(wordlist);
bxx = new BufferedReader(fxx);
lxx = new LinkedList<String>();
String word;
while ( (word = bxx.readLine()) != null)
{
lxx.add(word);
}
bxx.close();
}
public boolean inTheList (String theWord)
{
for(int i =0 ; i < lxx.size(); i++)
{
if (theWord.compareToIgnoreCase(lxx.get(i)) == 0)
{
return true;
}
}
return false;
}
}
Run Code Online (Sandbox Code Playgroud)