5 ways to Convert Java 8 Stream to List - Example, Tutorial
One of the common problems while working with Stream API in Java 8 is how to convert a Stream to List in Java because there is no toList() method present in the Stream class. When you are processing a List using Stream's map and filter method, you ideally want your result in some collection so that you can pass it to other parts of the program. Though java.util.stream.Stream class has toArray() method to convert Stream to Array, but there is no similar method to convert Stream to List or Set. Java has a design philosophy of providing conversion methods between new and old API classes e.g. when they introduced Path class in JDK 7, which is similar to java.io.File, they provided a toPath() method to File class.
تعليقات
إرسال تعليق