Java 中串聯字串的最佳方法。


Java 中串聯字串的最佳方法是 concat() 方法。

此方法將一個 String 追加到另一個 String 的末尾。該方法返回一個 String,其中包含傳遞到此方法的 String 的值,附加到用於呼叫此方法的 String 的末尾。

示例

即時演示

public class Test {
   public static void main(String args[]) {
      String s = "Strings are immutable";
      s = s.concat(" all the time");
      System.out.println(s);
   }
} 

輸出

Strings are immutable all the time

更新於:26-Feb-2020

147 次瀏覽

開啟你的 職業生涯

透過完成課程並獲得認證

開始
廣告
© . All rights reserved.