This example will demonstrate how to read a text file which is a variation of text file into an array list. Using the popular song "You are my sunshine" lyrics stored in a text file we will use various techniques of reading the file in java using a buffered reader, file scanner, java 8 file stream, google guava and apache commons.
Straight up Java
Using a bufferedreader we will read a text file in java loading each line into an arraylist.
Using a scanner we will read a text file in java and while there is more lines we will add it to an arraylist.
We will use the Files utility class introduced in java 7 and call lines which will read all lines of a file as a stream. Then we will convert the stream to an arralist.
Using guava we will read a text file.
Using apache commons we will read the context of a text file into an arraylist.