Groovy基本类型与运算符

  1. 字符串

    1.1字符串段落

def s = """Groovy
           Grails
           JAVA
           """

输出结果:
Groovy
Grails
JAVA

    1.2字符串运算符操作:                                                                     

//乘法 
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数字运算

运算符 名称 方法
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()

 

posted @ 2016-01-29 17:47  muzi1994  阅读(902)  评论(0编辑  收藏  举报