学堂 学堂 学堂公众号手机端

java两个字符串怎么拼接

lewis 3年前 (2022-02-16) 阅读数 5 #技术

在Java中可以使用加号操作符(+)来拼接两个字符串。例如:

String str1 = "Hello";
String str2 = "World";
String result = str1 + " " + str2;
System.out.println(result); // Output: Hello World

另外,还可以使用concat()方法来拼接字符串。例如:

String str1 = "Hello";
String str2 = "World";
String result = str1.concat(" ").concat(str2);
System.out.println(result); // Output: Hello World

版权声明

本文仅代表作者观点,不代表博信信息网立场。

热门