I have a data file which is comprised of rows of data, newline separated. I need to read the contents of the file into an array of Strings, and I would like to efficiently create the array at the correct size. Is it most efficient to
- Use an ArrayList,
- Scan through the file using BufferedReader, marking the start, counting lines and then reseting back to the mark,
or - ???
Use an
ArrayList(your option #1). Read in your text file line by line withBufferedReader‘sreadLine()method. It’s simple, efficient and maintainable.