Tuesday, September 15, 2020

How To Convert String To Byte Array and Vice Versa In Java 8

1. Overview

In this article, you will learn how to convert String to Byte[] array and vice versa in java programming.

First, let us explore the different ways using String.getBytes(), Charset.encode(), CharsetEncoder methods to convert String to a byte array, and last using java 8 Base64 api.

In the next section, you'll find similar methods for byte array to String.

How To Convert String To Byte Array and Vice Versa In Java 8

Thursday, September 10, 2020

Java Optional as Return Type

1. Overview

In this article, you'll learn how to use Optional as a return type in java 8.  Let us explore the most useful methods when working with Optional objects.

And also where Option can not fit and the scenarios where you should not use Optional in java.

Optional is added in java 8 to make clean the code and to easy way to work with the null values.

Let us jump into the Optional return type and its most important methods.

We've already covered in-depth about Optional API

Java Optional as Return Type

Tuesday, September 8, 2020

Filtering a Stream of Optionals in Java (With Examples)

1. Introduction


In this article, You'll be learning how to remove or filter the non-empty values from Stream of Optionals from Optional API.

Usually, you work with Stream of Strings or Stream of custom objects. But, there are some cases where you frequently work with Optional values.

Java 8 has come up with a new Optional API which is to avoid the NullPointerExceptions and others as well. Actually, our real value will be wrapped into an Optional instance.

Filtering a Stream of Optionals in Java


Removing the empty or nullable values from the list can be done in multiple ways in Java 8 and Java 9 concepts.