The List is a structure used to store a collection of data items. In Groovy, the List holds a sequence of object references. Object references in a List occupy a position in the sequence and are distinguished by an integer index. A List literal is presented as a series of objects separated by commas and enclosed in square brackets.
To process the data in a list, we must be able to access individual elements. Groovy Lists are indexed using the indexing operator . List indices start at zero, which refers to the first element.
Following are some example of lists −
In this chapter, we will discuss the list methods available in Groovy.
|Sr.No.||Methods & Description|
Append the new value to the end of this List.
Returns true if this List contains the specified value.
Returns the element at the specified position in this List.
Returns true if this List contains no elements
Creates a new List composed of the elements of the original without those specified in the collection.
Creates a new List composed of the elements of the original together with those specified in the collection.
Removes the last item from this List
Removes the element at the specified position in this List.
Create a new List that is the reverse the elements of the original List
Obtains the number of elements in this List.
Returns a sorted copy of the original List.