JAVA 8 / CATATAN</>↗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 / CATATAN</>↗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; […]
JAVA 8 / CATATAN</>↗Java 808 Jan 2024
The Stream.generate() method in Java is used to create an infinite stream of data, typically used when the programmer needs a limitless supply of data to be processed. Here’s an example of how you might use Stream.generate(): package org.kodejava.util; import java.util.stream.Stream; public class StreamGenerate { public static void main(String[] args) { Stream<String> stringStream = Stream.generate(() […]
JAVA 8 / CATATAN</>↗Java 808 Jan 2024
Pattern.splitAsStream() in Java is a method that allows us to split a string into a stream of substrings given a regex pattern. This can be useful when we’re working with large strings, and we want to process the substrings in a functional style using Java Streams. Here’s a basic example of how you can use […]
IO / CATATAN</>↗IO08 Jan 2024
The Files.walk() method in Java is a handy method when it comes to reading directory contents. Files.walk() method returns a Stream object that you can use to process each of the elements (files or directories) in the directory structure. This method walks the file tree in a depth-first manner, starting from the given path that […]
CORE API / CATATAN</>↗Core API08 Jan 2024
In Java, you can use the Files.list() method to list all files in a given directory. Files.list(Path dir) is a method in the java.nio.file.Files class. This method returns a Stream that is lazily populated with Path by walking the directory tree rooted at a given starting file. The file tree is traversed depth-first, the elements […]