Watch This Video
http://docs.groovy-lang.org/latest/html/gapi/groovy/lang/Range.html
// java
for (int x=1; x<=10; x++)
{
print x
}
println" "
println"*****"
for (int x=10; x>=1;x--){
print x
}
println" "
def list=['a','b','c','d']
for(int i=0; i<list.size();i++){
print list[i]
}
//Groovy
Range r=1..10
println r
println r.class.name
for (i in r){
print i
}
print r.from
print r.to
assert(0..10).contains(0)
assert(0..10).contains(1)
assert(0..10).contains(11)==false
assert(0..<10).contains(0)
assert(0..<10).contains(10)==false
Date today =new Date()
Date oneWeekAway=today +7
println today
println oneWeekAway
Range days=today..OneWeekAway
println days
for(j in days){
print j
}
Range t='a'..'z'
println t
for(j in t){
print j
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.