Last active
March 31, 2016 23:03
-
-
Save curtkim/4854893a78c95960e414 to your computer and use it in GitHub Desktop.
groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[run groovy script by java command] | |
java -cp lib/groovy-all-1.8.0.jar groovy.ui.GroovyMain test.groovy | |
nohup java -Duser.timezone=Asia/Seoul -cp lib/*: groovy.ui.GroovyMain script/findBadGps.groovy >> system.log 2>> error.log & | |
[String Interpolation] | |
value = 6 | |
println "The value is $value." | |
[loop] | |
for ( i in 1..10 ) { | |
println i | |
} | |
for ( i in 0..<10 ) { | |
println i | |
} | |
for ( i in [2, 3, 5, 7, 11] ) { | |
println i | |
} | |
[each] | |
[2, 3, 5, 7, 11].each { println it } | |
[2, 3, 5, 7, 11].each { prime -> println prime } | |
[2, 3, 5].eachWithIndex { p, i -> println "$i: $p" } | |
[a:1, b:2, c:3].each { println "key: ${it.key}, value: ${it.value}" } | |
[a:1, b:2, c:3].each { k, v -> println "key: $k, value: $v" } | |
[regexp] | |
"Hello World!" ==~ /.*World.*/ // true | |
matcher = ( "email@address.com" =~ /(\w+)@([\w\.]+)/ ) | |
matcher[0][1] // Returns "email" | |
matcher[0][2] // Returns "address.com" | |
[File] | |
new File("d:/").eachFile { println it } | |
new File("d:/").eachFileMatch(~/.*\.java/) { println it } | |
new File("test.txt").getText() | |
new File("test.txt").eachLine { println it } | |
[collection] | |
[2, 3, 5, 7, 11].find { it > 6 } | |
[2, 3, 5, 7, 11].findAll { it > 6 } | |
[2, 3, 5, 7].collect { it+1 } | |
[2, 3, 5, 7].join(" ") | |
def wordList = ['Apple', 'Banana', 'Cat'] | |
def wordCountMap = wordList.collectEntries{ [(it):it.length()] } | |
[thread] | |
thread = Thread.start { doSomething(); } | |
[misc] | |
[1, 2, null, 4].each { println it?.class } | |
http://geek.starbean.net/?page_id=202 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment