What is List reverse() in Groovy?

reverse() is a function in Groovy that creates a new list that is the reverse of the elements of the original list.

Syntax


List reverse() 

Parameters

The function takes in no parameter.

Return value

The function returns the reversed list.

Code

class Main {
static void main(String[] args) {
def list = [1, 2, 3, 4]
def reverselist = list.reverse()
println(reverselist)
}
}

Output

[4, 3, 2, 1]

Free Resources