首页javastringJava Data Type - 如何将原始数据类型转换为String

Java Data Type - 如何将原始数据类型转换为String

我们想知道如何将原始数据类型转换为String。

//The String class has an overloaded valueOf()  static method to 
//get the string representation of the values of any primitive data type or any object. For example,

public class Main {
  public static void main(String[] args) {
    String s1 = String.valueOf('C'); // s1 has "C"
    String s2 = String.valueOf("10"); // s2 has "10"
    String s3 = String.valueOf(true); // s3 has "true"
    String s4 = String.valueOf(2014); // s4 has "2014"
  }
}