String to boolean in java

Java convert string to boolean using Boolean.parseBoolean() method package com.w3schools; public class StringToBoolean { public static void main(String args[]){ String str1 = “false”; String str2 = “true”; //convert string to boolean boolean var1 = Boolean.parseBoolean(str1); boolean var2 = Boolean.parseBoolean(str2); System.out.println(“Boolean value of str1 is: “+var1); System.out.println(“Boolean value of str2 is: “+var2); } } Output: Boolean … Read more

Long to string in java

Java convert long to string using Long.toString() method package com.w3schools; public class LongToString { public static void main(String args[]){ long var = 765123; //convert long to string String str = Long.toString(var); System.out.println(“String is: “+str); } } Output: String is: 765123 Download this example. Java convert long to string using String.valueOf() method package com.w3schools; public class … Read more

String to long in java

Java convert string to long using Long.parseLong() method package com.w3schools; public class StringToLong { public static void main(String args[]){ String str = “578115”; //convert string to long long num = Long.parseLong(str); System.out.println(num); } } Output: 578115 Download this example. Java convert string to long using Long.valueOf() method package com.w3schools; public class StringToLong { public static … Read more

Double to string in java

Java convert double to string using toString() method package com.w3schools; public class DouleToString { public static void main(String args[]){ double var = 551.101; String str = Double.toString(var); System.out.println(“String is: “+str); } } Output: String is: 551.101 Download this example. Java convert double to string using valueOf() method package com.w3schools; public class DouleToString { public static … Read more

Java String to double

Java converts string to double using Double.parseDouble(String) package com.w3schools; public class StringToDouble { public static void main(String args[]){ String str=”546.307″; //convert String to double double var= Double.parseDouble(str); System.out.println(var); } } Output 546.307   Java converts string to double using Double.valueOf(String) package com.w3schools; public class StringToDouble { public static void main(String args[]){ String str=”546.307″; //convert String … Read more

Java Int to string

Java int to string example using Integer.toString() The Integer.toString() method is used to convert int to string in Java. It takes an integer value as an argument and returns a string representing of it. package com.w3schools; public class IntToString { public static void main(String args[]){ int num = 123; String str = Integer.toString(num); System.out.println(“String is: … Read more

Java String to integer with leading zeros

The format() method of the String class is used to convert string to integer with leading zeros. Example: package com.w3schools; public class StringToInt { public static void main(String args[]){ String str=”000000575″; /* String to int conversion with leading zeroes * the * the number, this ensures the leading zeroes */ str = String.format(” System.out.println(“Output String: … Read more

Java String to int

Java string to int example using Integer.parseInt() The Integer.parseInt() method is used to convert string to int in Java. It returns a primitive int value. It throws a NumberFormatException when all the characters in the String are not digits. Note: The first character in the string can be a minus ‘-‘ sign. Example: package com.w3schools; … Read more

check if a file is hidden java program

The isHidden() method of File class is used to check if a file is hidden in java. It returns true if the specified file is hidden else return false. Example: package com.w3schools;   import java.io.File;   public class HiddenFileTest { public static void main(String args[]){ try { //File File file = new File("D:/Test files/newTest.txt"); //Check … Read more

Categories IO

make a read only file writable java

The setWritable() method of File class is used to make a read only file writable in java. It takes a boolean value as a parameter. Example: package com.w3schools;   import java.io.File;   public class WritableFileTest { public static void main(String args[]){ try { //File File file = new File("D:/Test files/newTest.txt"); //Check the file is writable … Read more

Categories IO