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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。