I was wondering how to refer to the result of a lambda in Java? This is so I can store the results into an ArrayList
, and then use that for whatever in the future.
The lambda I have is:
try {
Files.newDirectoryStream(Paths.get("."),path -> path.toString().endsWith(".txt"))
.forEach(System.out::println);
} catch (IOException e) {
e.printStackTrace();
}
and inside the .forEach()
I want to be able to assign each file name to the array in turn, for example, .forEach(MyArrayList.add(this))
Thanks for any help in advance!