Java字符串concat()方法將一個字符串連接到另一個字符串的末尾。此方法返回一個字符串,該字符串的值將傳遞給該方法,並附加到該字符串的末尾。簽名:
public String concat(String anostr)
參數:
anostr- string to be concatenated at the end of the another string.
返回:
combination of two strings is returned.
例:展示concat()方法的用法原理
// Java program to demonstrate
// working of concat() method
class Gfg {
public static void main(String args[])
{
String s = "Gfg";
s = s.concat("! is the best.");
System.out.println(s);
}
}
輸出:
Gfg! is the best.
// Java program to demonstrate
// working of concat() method
class Gfg {
public static void main(String args[])
{
String s = "Gfg";
// We must explicitly assign result
// of s.concat() to s. Since not
// assigned to s, s does not change.
s.concat("! is the best.");
System.out.println(s);
}
}
輸出:
Gfg
相關用法
- Java Guava Longs.concat()用法及代碼示例
- Java Guava Doubles.concat()用法及代碼示例
- Java Guava Shorts.concat()用法及代碼示例
- Java Guava Bytes.concat()用法及代碼示例
- Java Guava Chars.concat()用法及代碼示例
- Java Guava Floats.concat()用法及代碼示例
- Java Guava Booleans.concat()用法及代碼示例
- Java DoubleStream concat()用法及代碼示例
- Java Stream.concat()用法及代碼示例
- Java LongStream concat()用法及代碼示例
- Java IntStream concat()用法及代碼示例
- Java Guava Ints concat()用法及代碼示例
- Java String format()用法及代碼示例
- Java String join()用法及代碼示例
注:本文由純淨天空篩選整理自Niraj_Pandey大神的英文原創作品 Java String concat() with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。