我拿了一个文本文件并将其放在一个数组中。但是,我想在数组中搜索一个字符串(单词)。就我而言,我想使用扫描仪从用户那里获取输入,然后在数组中搜索字符串匹配。怎样才能完成这样的任务?
public static void main(String[]args) throws IOException
{
//Scanner scan = new Scanner(System.in);
//String stringSearch = scan.nextLine();
List<String> words = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new FileReader("File1.txt"));
String line;
while ((line = reader.readLine()) != null) {
words.add(line);
}
reader.close();
System.out.println(words);
}
我的输出:
[CHAPTER I. Down the Rabbit-Hole, Alice was beginning to get very tired of sitting by her sister on the, bank, and of having nothing to do:]