Conversion of any type to String use,
a. String.valueOf( )
b. toString( )
Conversion of String to any type use,
a. any_type.parse()
Converting any type to String:
public class Conversion {public static void main(String[] args) {int a=10;double b=5.5;//Converting other types to StringString s1=String.valueOf(a);String s2=String.valueOf(b);//concatination of two stringsString s3=s1+s2;System.out.println(s3);}}
Output:
105.5
Converting String to any type:
public class Conversion {public static void main(String[] args) {String s1="10";String s2="11.5";//converting String to Integerint a=Integer.parseInt(s1);//converting String to Doubledouble b=Double.parseDouble(s2);double res=(double)a+b;System.out.println("Result= "+res);}}
Output
Result= 21.5