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.