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()
相关文章
相关标签/搜索