以多少種方式能在 java 中建立 String 物件?


你可以透過 - 建立一個字串

步驟 1 - 將用 “” 括起來的字串值賦給一個 String 型別的變數。

String message = "Hello Welcome to Tutorialspoint";

步驟 2 - 使用 new 關鍵字建立 String 類的一個物件,並將字串值作為其建構函式的引數傳遞。

String message = new String ("Hello Welcome to Tutorialspoint");

步驟 3 - 將一個字元陣列傳遞給 String 建構函式。

char arr[] = {'H','e','l','l','o'};
String message = new String(arr);

更新日期: 2019 年 7 月 30 日

935 次瀏覽

開啟你的 事業

完成課程以獲得認證

立即開始
廣告
© . All rights reserved.