codecamp

Groovy 字符串连接

语法

字符串的串联可以通过简单的\'+\'运算符来完成。

String+String

参数 - 参数将为2个字符串作为& plus;的左右操作数。 运算符。

返回值 - 返回值是一个字符串

例子

以下是Groovy中字符串连接的示例。

class Example {
   static void main(String[] args) {
      String a = "Hello";
      String b = "World";
		
      println("Hello" + "World");
      println(a + b);
   }
}

当我们运行上面的程序,我们将得到以下结果 -

HelloWorld
HelloWorld
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定