Java 8 Stream – Read a file line by line
In Java 8, you can use Files.lines to read file as Stream. A new method lines() has been added since 1.8, it lets BufferedReader returns content as Stream.
Favourite tutorials for developers
In Java 8, you can use Files.lines to read file as Stream. A new method lines() has been added since 1.8, it lets BufferedReader returns content as Stream.
In Java 8, we can use the Stream.reduce() to sum a list of BigDecimal. Java example to sum a list of BigDecimal values, using a normal for loop and a…
In Java 8 Stream, the findFirst() returns the first element from a Stream, while findAny() returns any element from a Stream.
Code snippets to convert a primitive array int to a List. In Java 8, you can use the Stream APIs to do the boxing and conversion. You can’t use the…
In Java 8, you can either use Arrays.stream or Stream.of to convert an Array into a Stream. For object arrays, both Arrays.stream and Stream.of returns the same output. For object…
In Java 8, we can use .toArray() to convert a Stream into an Array.
A Java 8 example to show you how to convert a Stream to a List via Collectors.toList Java8Example1.java Output Yet another example, filter a number 3 and convert it to…
Filter a null value from a Stream by using Stream.filter(x -> x!=null). Alternatively, filter with Objects::nonNull method reference
In Java 8, we can use Stream.iterate to create stream values on demand, so called infinite stream. The stream.iterate was enhanced in Java 9. It supports a predicate (condition) as…
The following 3 Java examples will print a list of all the prime numbers up to 1,000: 1 - Java 8 Stream and BigInteger, 2 - Plain old Java ,…