Let's take a look at the java.util.stream package added to Java 8. https://www.developer.com/java/data/stream-operations-supported-by-the-java-streams-api.html
Common methods that can be used in all streams are defined in Base Stream and Stream is a stream that processes object elements, IntStream, LongStream, and DoubleStream are streams that process basic types of int, long, and double elements, respectively.
List<String> list = Arrays.asList("Ah", "I", "U");
Stream<String> stream = list.stream(); // Collection . stream()
String[] strArray = {"Ah", "I", "U"};
Stream<String> stream = Arrays.stream(strArray);
int[] intArray = {1, 2, 3, 4};
IntStream intStream = Arrays.stream(intArray);
IntStream stream = IntStream.rangeClosed(1, 100);
public static void main(String[] args) throws IOException{
Path path = Paths.get("src/stream/list.txt");
Stream<String> stream = Files.lines(path, Charset.defaultCharset());
stream.forEach(System.out :: println);
System.out.println();
File file = path.toFile();
FileReader fileReader = new FileReader(file);
BufferedReader br = new BufferedReader(fileReader);
stream = br.lines();
stream.forEach(System.out :: println);
}
public static void main(String[] args) throws IOException{
Path path = Paths.get("c://");
Stream<Path> stream = Files.list(path);
stream.forEach(p -> System.out.println(p.getFileName()));
}
Recommended Posts