Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env groovy
- println "Hello from the shebang line"
- // ## LISTS
- // default = ArrayList
- def arrayList = [1, 2, 3]
- assert arrayList instanceof java.util.ArrayList
- // linkedList
- def linkedList = [2, 3, 4] as LinkedList
- assert linkedList instanceof java.util.LinkedList
- LinkedList otherLinked = [3, 4, 5]
- assert otherLinked instanceof java.util.LinkedList
- def letters = ['a', 'b', 'c', 'd']
- assert letters[0] == 'a'
- assert letters[1] == 'b'
- // access the last element of the list with a negative index: -1
- assert letters[-1] == 'd'
- assert letters[-2] == 'c'
- letters[2] = 'C'
- assert letters[2] == 'C'
- // use the << leftShift operator to append an element at the end of the list
- letters << 'e'
- assert letters[ 4] == 'e'
- assert letters[-1] == 'e'
- // access two elements at once, returning a new list containing those two elements
- assert letters[1, 3] == ['b', 'd']
- // Use a range to access a range of values from the list, from a start to an end element position
- assert letters[2..4] == ['C', 'd', 'e']
- // multi-dimensional list
- def multi = [[0, 1], [2, 3]]
- assert multi[1][0] == 2
- // ## ARRAYS
- String[] arrStr = ['Ananas', 'Banana', 'Kiwi']
- def numArr = [1, 2, 3] as int[]
- // ## MAPS
- def colors = [red: '#FF0000', green: '#00FF00', blue: '#0000FF']
- assert colors['red'] == '#FF0000'
- assert colors.green == '#00FF00'
- colors['pink'] = '#FF00FF'
- colors.yellow = '#FFFF00'
- assert colors.pink == '#FF00FF'
- assert colors['yellow'] == '#FFFF00'
- assert colors instanceof java.util.LinkedHashMap
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement