Convert a Stream to Array using Java 8

In the code below converts a Stream to an Array with Java 8. The Java 8 Library contains the .toArray() function that makes it easier to convert Datatypes to an array type. Convert a stream to an Array in Java import java.util.Arrays; public class Main { public static void main(String[] args) { String str =... » read more

Count the Number of Bits Set to One using Java

In this article, we’ll be counting the number of bits set to one using Java. To make it more transparent, let’s take number 6 as an example. Number 6 is represented as 110 in binary. From our example, the output is 2, as there are two ones in the binary of the converted number. In... » read more

Convert Integer Values to Byte, Character, and Float using Java

In Java, just like most programming languages, we can convert one data type into another type using Type Conversion. Mainly, there are two types of conversions, and in this example, we’ll be using both of them. First one is automatic type conversion, which automatically converts compatible data types into another type using Java — for... » read more

Find Sum of N Numbers Using Recursion in Java

In this article, you’ll learn how to get the sum of n numbers using a recursion function. Recursion function is said to be calling itself over and over again in the application. By using recursive functions, we can remove the side effects of the looping structures. It is essential to define the base case or... » read more

Convert int to BigInteger in Java

The code below is to convert int to an integer, as well as an integer to a BigInteger. This example uses the namespace java.math. import java.math.BigInteger; public class IntConvertor{ public static void main(String[] args) { int input = 10; //Print out System.out.println(input); // convert int to Integer Integer integer = Integer.valueOf(input); //Print out System.out.println(integer); // convert... » read more