Java中連線字串的最佳方法


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

此方法將一個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

更新於: 2020年2月26日

147次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.