Creating Streams in Java
Learn to create Streams of primitives and objects in Java using some most popular ways. We will learn to create finite as well as infinite streams.
Learn to create Streams of primitives and objects in Java using some most popular ways. We will learn to create finite as well as infinite streams.
Learn to apply if-else logic in a Java 8 stream of elements to filter elements based on certain condition. The if-else condition can be applied using the lambda expressions in stream filter() function.
Java 8 stream distinct by multiple fields example. Learn to find distinct objects from a stream by comparing multiple fields or creating a custom key class.
Learn to get the Stream of random numbers in Java using the Random and SecureRandom methods ints(), longs() and doubles().
Learn to find min and max date, number, Char, String or object from a stream of items in easy steps using Comparator.comparing().
To count the number of elements in stream in Java 8, use either the Stream.count() or Collectors.counting() methods.
To convert primitives intstream or longstream to List, Set or Array, you can adapt one of the following ways given with examples.
In java 8, to convert a stream of primitives to collection, you must first box the elements in their wrapper class and then collect them i.e. boxed stream.
Date and time handling has always been a pain area for Java developers. The new Date-Time API added in Java 8 changed the way, we interact with date and time in Java. New Date API is a very powerful and much-needed improvement. The only thing missing was, getting a stream …
Learn new Java 9 improvements in Stream API, i.e., the takeWhile / dropWhile, ofNullable, and iterate methods with examples.
Using java 8 stream API, you can use stream.distinct() method to filter or collect all distinct elements from a collection. Let’s learn how to find distinct elements with java stream API.
In this example, we will learn to use java 8 APIs along with Files.list() and DirectoryStream to list all files present in that directory.
Java Streams can be defined as a sequence of elements from a source that supports aggregate operations on them. The source refers to a collection or array.
Introduced in Java 8, a functional interface is simply an interface that has exactly one abstract method. Learn more about functional interfaces in this tutorial.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.