要连接一个String和一些整数值,您需要使用+运算符。
假设以下是字符串。
String str = "Demo Text";
现在,我们将连接整数值。
String res = str + 1 + 2 + 3 + 4 + 5;
以下是最后一个示例。
public class Demo {
   public static void main(String[] args) {
      String str = "Demo Text";
      System.out.println("String = "+str);
      String res = str + 1 + 2 + 3 + 4 + 5;
      System.out.println(res);
   }
}输出结果
String = Demo Text Demo Text12345