Java String concat()方法將一個String
附加到另一個String
的末尾。 該方法返回一個連接後的String
值。
語法
以下是此方法的語法 -
public String concat(String s)
參數
s
- 連接到此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
上一篇:
Java String類
下一篇:
Java快速入門