我有一个包含字符串的大文件。所有行都应该添加到我的代码中的列表中。最快的方法是什么?我找到了这个,但我不知道如何使用它逐行读取。
我认为内置解决方案应该足够快:
List<String> allLines = Files.readAllLines(Paths.get("location/of/your/file"));
List<String>
创建List<YourClass>
吗?如果是,那么这个列表的唯一目的是创建其他列表还是你还需要在其他地方使用它? - PshemoFiles.lines(Paths.get("location/of/your/file")).parallel()
。顺便说一下,map(c -> new MyClass(c))
可以用更简短、更易读的方式替换为.map(MyClass::new)
。 - Pshemocopy filename nul
命令,在Linux上使用cp filename /dev/null
命令。将这个时间从您的应用程序时间中减去,以查看您的应用程序使用了多少时间。 - Klitos Kyriacou
reader.readLine()
来读取行。 - Evan LaHurd