Java 8

Java Stream findAny()

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() Example

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.

Java IntPredicate Example

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.

Guide to IntStream in Java

Java IntStream represents a stream of primitive int-valued elements supporting sequential and parallel aggregate operations.

Java Stream toArray() Example

Learn to convert stream to array using Stream.toArray() API. This post contains multiple examples for collecting stream elements to array under different usecases.

Using ‘if-else’ Conditions with Java 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 forEach()

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.

Boxed Streams in Java

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.

Java 8 Method Reference (with Examples)

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.

Java WatchService Tutorial

Learn to register for changes in a directory, sub-directories and files using the Java WatchService API, handle the changes and cancel it.

Guide to Java 8 Optional

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 Base64 Encode and Decode Example

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 Exact Arithmetic Operations Support in Math Class

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 …

Java String.join()

Since Java 8, we can use String.join() method to concatenate strings with a specified delimiter. For advanced usages, use StringJoiner class.

Java Comparator with Lambda

Learn to create a Comparator instance with lambda expressions, method references and chaining multiple comparators for complex comparisons.

Java 8 Predicate Example

Java Predicates are boolean-valued statements that may be true or false depending on the test argument. Predicates are used to filter Streams.

Java Default Methods Tutorial

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 in Java

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 Date Time API

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.

About Us

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.