How to convert String to int in java
What you will learn here about java conversion
- How to convert String to byte in java
- How to convert String to short in java
- How to convert String to int in java
- How to convert String to long in java
- How to convert String to float in java
- How to convert String to double in java
- How to convert String to boolean in java
How to convert String to byte in java
The example of how to convert String to byte in java is given below
public class String2Byte{ public static void main(String[] args) { String value="10"; byte number=Byte.parseByte(value); System.out.println("byte representation of \""+value+"\" is "+number); } }
OUTPUT
byte representation of “10” is 10
How to convert String to short in java
The example of how to convert String to short in java is given below
public class String2Short { public static void main(String[] args) { String value="100"; short number=Short.parseShort(value); System.out.println("short representation of \""+value+"\" is "+number); } }
OUTPUT
short representation of “100” is 100
How to convert String to int in java
The example of how to convert String to int in java is given below
public class String2Int { public static void main(String[] args) { String value="10"; int number=Integer.parseInt(value); System.out.println("Interger representation of \""+value+"\" is "+number); } }
OUTPUT
Interger representation of “10” is 10
How to convert String to long in java
The example of how to convert String to long in java is given below
public class String2Long { public static void main(String[] args) { String value="100000"; long number=Long.parseLong(value); System.out.println("long representation of \""+value+"\" is "+number); } }
OUTPUT
long representation of “100000” is 100000
How to convert String to float in java
The example of how to convert String to float in java is given below
public class String2Float { public static void main(String[] args) { String value="10.00"; float number=Float.parseFloat(value); System.out.println("float representation of \""+value+"\" is "+number); } }
OUTPUT
float representation of “10.00” is 10.0
How to convert String to double in java
The example of how to convert String to double in java is given below
public class String2Double { public static void main(String[] args) { String value="100.0003"; double number=Double.parseDouble(value); System.out.println("double representation of \""+value+"\" is "+number); } }
OUTPUT
double representation of “100.0003” is 100.0003
How to convert String to boolean in java
The example of how to convert String to boolean in java is given below
public class String2Boolean { public static void main(String[] args) { String value="true"; boolean number=Boolean.parseBoolean(value); System.out.println("boolean representation of \""+value+"\" is "+number); } }
OUTPUT
boolean representation of “true” is true