At the moment I want to write a program that would put the text from the txt file into a two-dimensional array ArrayList<ArrayList<String>> (an array of strings in which lie arrays of words).
The goal, to achieve the output:
[ [набор слов 1й строки] [набор слов 2й строки] [ 3й...] [...n] ] I'm currently out:
[ [набор слов всех строк] [набор слов всех строк] [...] ] Code:
ArrayList<ArrayList<String>> str = new ArrayList<ArrayList<String>>(); ArrayList<String> words = new ArrayList<String>(); Scanner s = new Scanner(new File("C:\\Text.txt")); while (s.hasNextLine()) { // проверяем, есть ли строка String line; // временная переменная line = s.nextLine(); StringTokenizer st = new StringTokenizer(line, " "); // дробим строку на слова while (st.hasMoreTokens()) { words.add(st.nextToken()); // заносим слова в ArrayList words } str.add(words); // заносим ArrayList words в ArrayList str } System.out.println(str); Please, stick your nose where the error? How to write correctly?