사용자 도구

사이트 도구


groovy:list

문서의 이전 판입니다!


Groovy List

기본값 줘서 리스트 생성

def lazy = ['abc', 42].withDefault { 'default' } // Or .withLazyDefault {} 접근전에는 null, 접근시에는 'default'
def eager = ['abc', 42].withEagerDefault { 'default' } // 접근전부터 'default'
 
def sample = [1,2,3].withDefault { index -> // index를 이용해 값 넣기
    index % 2
}

Iterable의 처음/마지막 값

sublist

def list = 0..100
list[0,5] // 0~5
list[1..-1] // 1~100까지
list[1..5,10,20] // 0, 1, 2, 3, 4, 5, 10, 20

each

[1, 2, 3].each{ println "Item: $it" }
['a', 'b', 'c'].eachWithIndex{ it, i -> println "$i: $it" } // index 를 가지고 each 돌기. index는 0 부터 시작
groovy/list.1354091624.txt.gz · 마지막으로 수정됨: 2012/11/28 17:33 저자 kwon37xi