在 java 中將單個字元追加到字串或 char 陣列末尾?


StringBuffer 類中的 append() 方法會將指定的字串追加到當前字串緩衝區的內容中。使用這種方法,可以將單個字元追加到 java 中的字串或 char 陣列中。

範例

public class Test {
   public static void main(String args[]) {
      StringBuffer sb = new StringBuffer("Hi hello how are yo");
      sb.append("u");
      System.out.println(sb);
   }
}

輸出

Hi hello how are you

更新於: 2020 年 2 月 26 日

2K+ 瀏覽

啟動你的 職業

完成課程獲得認證

開始
廣告
© . All rights reserved.