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 …
Month: April 2021
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 …
Java Program to convert int type variables to long In this program, we will learn to convert integer (int) variables into the long variables in Java. Example 1: Java Program to Convert int to long using Typecasting class Main{ public static void main(String[] args){ // create int variables int a = 25; int b …
Java Program to convert long type variables into int In this program, we will learn to convert the long variable into an integer (int) in Java. Example 1: Java Program to Convert long to int using Typecasting class Main{ public static void main(String[] args){ // create long variables long a = 2322331L; long b …
Java Program to convert int type variables to char In this program, we will learn to convert the integer (int) variable into a character (char) in Java. Example 1: Java Program to Convert int to char class Main{ public static void main(String[] args){ // create int variables int num1 = 80; int num2 = …
Java Program to convert char type variables to int In this program, we will learn to convert the character (char) type variable into an integer (int) in Java. Example 1: Java Program to Convert char to int class Main{ public static void main(String[] args){ // create char variables char a = ‘5’; char b …
Java Program to Copy File In this tutorial, we will learn to copy files in Java. The Java File class doesn’t provide any method to copy one file to another. However, we can use Java I/O Streams to read content from one file and write to another. Example: Copy files using i/o streams import java.io.FileInputStream; import java.io.FileOutputStream; class …
Java Program to Get all Files Present in a Directory In this example, we will learn to list all the files and sub-directories present inside a directory. Example 1: Java Program to List all files import java.io.File; class Main{ public static void main(String[] args){ // creates a file object File file = new File(“C:\Users\Guest …
Java Program to Rename File In this tutorial, we will learn to rename file in Java. The Java File class provides the renameTo() method to change the name of the file. It returns true if the renaming operation succeeds otherwise returns false. Example: Rename a File in Java import java.io.File; class Main{ public static void main(String[] args){ // create …
Java Program to Create Directories In this example, we will learn to create directories in Java. The Java File class provides the mkdir() method to create a new directory. The method returns true if the new directory is created false if the directory already exists Example 1: Create a new directory in Java import java.io.File; class Main{ …