java中concat的用法是什么

在Java中,concat方法用于将一个字符串与另一个字符串连接起来,返回一个新的字符串。这个方法是在String类中定义的,具体用法如下:

String str1 = "Hello";
String str2 = "World";
String result = str1.concat(str2);

System.out.println(result); // 输出:HelloWorld

concat方法将str2字符串连接到str1字符串的末尾,返回一个新的字符串"HelloWorld"。需要注意的是,concat方法并不会修改原始字符串,而是返回一个新的字符串,因此在使用时需要将返回值赋给一个新的变量。

Both comments and pings are currently closed.

Comments are closed.

Powered by KingAbc | 粤ICP备16106647号-2 | Loading Time‌ 0.232