文字列を連結する方法
Javaでは複数の文字列を連結するには、文字列のconcat()メソッドまたは”+”演算子を使用できます。
concat()メソッドを使用します。
String str1 = "Hello";
String str2 = "World";
String result = str1.concat(str2);
System.out.println(result); // 输出 "HelloWorld"
「+」演算子を使用する:
String str1 = "Hello";
String str2 = "World";
String result = str1 + str2;
System.out.println(result); // 输出 "HelloWorld"
どちらの方法も、複数の文字列を1つの新しい文字列に結合します。