JAVA 8 / NOTES</>↗Java 810 Jan 2024
The peek method in Java’s Stream API is an intermediary operation. This method provides a way to inspect the elements in the stream as they’re being processed by other stream operations. However, it’s important to note that peek should only be used for debugging purposes, as it can be quite disruptive to the stream’s data […]
JAVA 8 / NOTES</>↗Java 810 Jan 2024
The map(), filter(), and reduce() methods are key operations used in Java Stream API which is used for processing collection objects in a functional programming manner. Java Streams provide many powerful methods to perform common operations like map, filter, reduce, etc. These operations can transform and manipulate data in many ways. map: The map() function […]
JAVA 8 / NOTES</>↗Java 809 Jan 2024
When using Java’s Stream.forEach() method, you might encounter checked exceptions. Checked exceptions can’t be thrown inside a lambda without being caught because of the Consumer functional interface. It does not allow for this in its method signature. Here is an example of how you might deal with an exception in a forEach operation: package org.kodejava.basic; […]
JAVA 8 / NOTES</>↗Java 809 Jan 2024
In Java, you can loop through a Stream by using the forEach() method provided by the Stream API. In the following example, we created a Stream of Strings. Each String represents a different programming language. The forEach() method accepts a Consumer, which is a functional interface representing an operation that accepts a single input argument […]
JAVA 8 / NOTES</>↗Java 808 Jan 2024
In Java, you can use IntStream, LongStream, or DoubleStream to create ranges of numbers as streams. For example, to create a range of integer numbers, we can call the range() static method of the IntStream interface. Here’s an example: package org.kodejava.util; import java.util.stream.IntStream; public class IntRangeExample { public static void main(String[] args) { IntStream.range(1, 11).forEach(System.out::println); […]
JAVA 8 / NOTES</>↗Java 808 Jan 2024
The Stream.iterate() method in Java is used to generate a Stream of elements based on some iterative logic. The simplest form Stream.iterate(initialValue, lambdaFunction) takes in an initial value and a UnaryOperator function to compute the next element in the series. Here’s an example of using `Stream.iterate()“ to create a Stream of incremental numbers: package org.kodejava.util; […]