1,int类型转换为字符串
三种方法:
1.) String s = String.valueOf(i);2.) String s = Integer.toString(i);3.) String s = "" + i;
2,double型转换为字符串
可以使用方法: Double.toString(double d)
注意,Double是double的包装类。
下面是代码示例:
Convert double To String In Java
public class ConvertDoubleToString {
public static void main(String[] args) {
double d = 1040.88;
// convert double to String type
System.out.println(Double.toString(d));
// convert double primitive to Double type
System.out.println(Double.valueOf(d));
}
}
public static void main(String[] args) {
double d = 1040.88;
// convert double to String type
System.out.println(Double.toString(d));
// convert double primitive to Double type
System.out.println(Double.valueOf(d));
}
}
Output
1040.88
1040.88
1040.88
1040.88