如何将此 ArrayList 的值转换为数组?所以它看起来像,
String[] textfile = ... ;
值是字符串(文本文件中的单词),并且有超过 1000 个单词。在这种情况下,我不能执行 words.add("") 1000 次。然后我怎样才能把这个列表放入一个数组中?
public static void main(String[]args) throws IOException
{
Scanner scan = new Scanner(System.in);
String stringSearch = scan.nextLine();
List<String> words = new ArrayList<String>(); //convert to array
BufferedReader reader = new BufferedReader(new FileReader("File1.txt"));
String line;
while ((line = reader.readLine()) != null) {
words.add(line);
}