Groovy基本類型與運算符

  1. 字符串

    1.1字符串段落spa

def s = """Groovy 
Grails JAVA """  輸出結果: Groovy Grails JAVA

            1.2 字符串操做運算符                    code

//乘法 
assert "hellohello" == "hello" * 2  
//減法
def st1 = "helloWorld" def st2 = "World"
assert "hello" == st1 - st2 //截取字符串
def st1 = "helloWorld"
assert "hello" == st1[0..4] assert "World" == st1[5..9] assert "World" == st1[-1..-5]   //從右邊截取字符串

           1.3數字運算ip

運算符 名稱 方法
a + b a.plus(b)
a | b a.minus(b)
a * b a.multiply(b)
a / b a.div(b)
a % b 取餘 a.mod(b)
a++ 後自增 a.next()
a-- 後自減 a.previous()
相關文章
相關標籤/搜索