Java字串轉換


String類有一個過載的valueOf()靜態方法來獲取任何原始資料型別或任何物件的值的字串表示。 例如,

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"
  }
}