Java example

Learn Java by Example: Java Program to Implement Binary Search Algorithm

Java Program to Implement Binary Search Algorithm In this example, we will learn to implement binary search algorithm in Java.   Example: Java Program to Implement Binary Search Algorithm import java.util.Scanner; // Binary Search in Java class Main{ int binarySearch(int array[], int element, int low, int high){ // Repeat until the pointers low and high …

Learn Java by Example: Java Program to Implement Bubble Sort algorithm

Java Program to Implement Bubble Sort algorithm In this example, we will learn to execute bubble sort algorithm in Java.   Example: Java Program to Implement Bubble Sort Algorithm // import the Class import java.util.Arrays; import java.util.Scanner; class Main{ // create an object of scanner // to take input from the user Scanner input = …

Learn Java by Example: Java Program to convert primitive types to objects and vice versa

Java Program to convert primitive types to objects and vice versa In this tutorial, we will learn to convert the primitive data types to their corresponding wrapper objects and vice versa in Java.   Example 1: Java Program to Convert Primitive Types to Wrapper Objects class Main{ public static void main(String[] args){ // create primitive …

Learn Java by Example: Java Program to convert string variables to double

Java Program to convert string variables to double In this tutorial, we will learn to convert the string variables into double in Java.   Example 1: Java Program to Convert string to double using parseDouble() class Main{ public static void main(String[] args){ // create string variables String str1 = “23”; String str2 = “456.6”; // …

Learn Java by Example: Java Program to convert string type variables into int

Java Program to convert string type variables into int In this program, we will learn to convert the String type variables into the integer (int) in Java.   Example 1: Java Program to Convert string to int using parseInt() class Main{ public static void main(String[] args){ // create string variables String str1 = “23”; String …

Learn Java by Example: Java Program to convert string type variables into boolean

Java Program to convert string type variables into boolean In this program, we will learn to convert the String type variables into boolean in Java.   Example 1: Convert string to boolean using parseBoolean() class Main{ public static void main(String[] args){ // create string variables String str1 = “true”; String str2 = “false”; // convert …

Learn Java by Example: Java Program to convert boolean variables into string

Java Program to convert boolean variables into string In this program, we will learn to convert the boolean type variables into string in Java.   Example 1: Convert boolean to string using valueOf() class Main{ public static void main(String[] args){ // create boolean variables boolean booleanValue1 = true; boolean booleanValue2 = false; // convert boolean …