Groovy - 字符串拼接



语法

可以使用简单的“+”操作符连接字符串。

String+String

参数 - 参数将为 + 操作符的左右操作数中的 2 个字符串。

返回值 - 返回值为字符串

范例

以下为 Groovy 中字符串连接的范例。

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

当我们运行上述程序时,将获得以下结果 -

HelloWorld
HelloWorld
groovy_strings.htm
广告
© . All rights reserved.