Size in Groovy

Find this useful? Support us: Star on GitHub 6
Category: Array | Language: Groovy

In Groovy, you can get the size of an array using the .size() or .length methods. Here are some examples:

1. Using .size() method:

def array = [1, 2, 3, 4, 5]
def size = array.size()
println size  // Output: 5

2. Using .length property:

def array = [1, 2, 3, 4, 5]
def length = array.length
println length  // Output: 5

In both examples, we defined an array and used the .size() and .length methods to obtain its size. The result is printed using the println statement.