I'm creating a program that allows users to interact with a file thats input. One of the options is to display the file. Below, I store the file into an arraylist first by creating arraylists consisting of lines, and then an inner arraylist separated of strings, separated by spaces.
Scanner sc = new Scanner(fileName);
while (sc.hasNextLine()) {
String line = sc.nextLine();
String[] words = {};
words = line.split(" ");
ArrayList<String> lineArray = new ArrayList<String>();
for (int i = 0; i < words.length; i++) {
lineArray.add(words[i]);
}
fileByLine.add(lineArray);
}
sc.close();
I'm trying to print the contents of the arraylist, called fileByLine, as they appear in the file, but I'm not sure how to. Any suggestion?
case '1':
for(int i = 0; i < fileByLine.size(); i++){
for(int j = 0; j < fileByLine.[i].size(); j++){
System.out.print(fileByLine[i][j]);
} System.out.println("");
} break;