Java reading a file into an ArrayList?

后端 未结 13 1142
醉话见心
醉话见心 2020-11-22 12:05

How do you read the contents of a file into an ArrayList in Java?

Here are the file contents:

cat
ho         


        
13条回答
  •  遥遥无期
    2020-11-22 12:59

    To share some analysis info. With a simple test how long it takes to read ~1180 lines of values.

    If you need to read the data very fast, use the good old BufferedReader FileReader example. It took me ~8ms

    The Scanner is much slower. Took me ~138ms

    The nice Java 8 Files.lines(...) is the slowest version. Took me ~388ms.

提交回复
热议问题