Java Optional orElse Vs. OrEleseGet (with Examples)
Java 8 Optional contains orElse() and orElseGet() methods that return a default value when the optional is empty. Learn the difference between both.
Java 8 Optional contains orElse() and orElseGet() methods that return a default value when the optional is empty. Learn the difference between both.
Learn to filter a Java HashMap by List of keys and collect the matching entries into a submap or matching values in a List.
Java 8 Stream.findAny() returns an Optional describing any element of Stream if Stream is non-empty. It returns an empty Optional if the stream is empty.
Java Stream findFirst() returns an Optional describing the first element of stream if Stream is non-empty, or an empty Optional if the stream is empty.
Learn to find the last element of a stream in Java 8 or later. We will learn to use finite as well as infinite streams as well.
Java 8 IntPredicate is a functional interface whose functional method is boolean test(int a). It can be considered a function returning true or false value.
Java IntStream represents a stream of primitive int-valued elements supporting sequential and parallel aggregate operations.
Learn to convert stream to array using Stream.toArray() API. This post contains multiple examples for collecting stream elements to array under different usecases.
Learn to use Stream sorted() method to sort a stream of elements in their natural order and also according to the provided Comparator.
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 forEach() is a utility function to iterate over a Collection (list, set or map) or Stream. It performs the specified Consumer action on each item in the Collection.
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.
Since Java 8, in simplest words, the method references are a way to refer to methods or constructors without invoking them. Learn the syntax with examples.
Learn to register for changes in a directory, sub-directories and files using the Java WatchService API, handle the changes and cancel it.
All of us must have encountered NullPointerException in our applications. It happens when you try to use an object that has not been initialized, initialized with null or does not point to any instance. In simple words, NULL simply means ‘absence of a value’. In this Java tutorial, we will …
Java 8 introduced ‘java.util.Base64‘ utility class that provides built-in support for performing base64 encoding and decoding operations as specified in RFC 4648 and RFC 2045. Let us explore Base64 encode and decode processes with various usecases with examples. 1. What is Base64? Base64 is a binary-to-text encoding scheme that converts …
Java 8 has brought many awesome features for java developers. Some of them I have already described in Comparator changes, Streams examples, Internal vs. external iterations, predicates, functional interfaces, default methods, lambda expressions and date and time API changes. All above changes were related to lambda expressions, which is the …
Since Java 8, we can use String.join() method to concatenate strings with a specified delimiter. For advanced usages, use StringJoiner class.
Learn to create a Comparator instance with lambda expressions, method references and chaining multiple comparators for complex comparisons.
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.
Java Predicates are boolean-valued statements that may be true or false depending on the test argument. Predicates are used to filter Streams.
In previous post, we learned about Lambda expressions and functional interfaces. Now, let’s move on the discussion and talk about another related feature i.e. default methods. Well, this is truly revolutionary for java developers. Till java 7, we have learned a lot of things about interfaces and all those things …
Lambda expressions are known to many of us who have worked on advanced languages like Scala. The term “lambda” has its origin in Lambda calculus that uses the Greek letter lambda (λ) to denote a function abstraction. Lambda expressions were introduced to Java as part of Java 8 release. 1. What are …
Java 8 contains the new Date and Time APIs/classes (JSR-310), called ThreeTen, which will change how you have been handling dates in Java.
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.