- Groovy - Meta Object Programming
- Groovy - Template Engines
- Groovy - Unit Testing
- Groovy - Command Line
- Groovy - Builders
- Groovy - Database
- Groovy - DSLS
- Groovy - JSON
- Groovy - JMX
- Groovy - XML
- Groovy - Annotations
- Groovy - Closures
- Groovy - Traits
- Groovy - Generics
- Groovy - Object Oriented
- Groovy - Exception Handling
- Groovy - Regular Expressions
- Groovy - Dates & Times
- Groovy - Maps
- Groovy - Lists
- Groovy - Ranges
- Groovy - Strings
- Groovy - Numbers
- Groovy - Optionals
- Groovy - File I/O
- Groovy - Methods
- Groovy - Decision Making
- Groovy - Loops
- Groovy - Operators
- Groovy - Variables
- Groovy - Data Types
- Groovy - Basic Syntax
- Groovy - Environment
- Groovy - Overview
- Groovy - Home
Groovy Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Groovy - Lists
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 pteral is presented as a series of objects separated by commas and enclosed in square brackets.
To process the data in a pst, we must be able to access inspanidual 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 psts −
[11, 12, 13, 14] – A pst of integer values
[‘Angular’, ‘Groovy’, ‘Java’] – A pst of Strings
[1, 2, [3, 4], 5] – A nested pst
[‘Groovy’, 21, 2.11] – A heterogeneous pst of object references
[ ] – An empty pst
In this chapter, we will discuss the pst methods available in Groovy.
Sr.No. | Methods & Description |
---|---|
1 | Append the new value to the end of this List. |
2 | Returns true if this List contains the specified value. |
3 | Returns the element at the specified position in this List. |
4 | Returns true if this List contains no elements |
5 | Creates a new List composed of the elements of the original without those specified in the collection. |
6 | Creates a new List composed of the elements of the original together with those specified in the collection. |
7 | Removes the last item from this List |
8 | Removes the element at the specified position in this List. |
9 | Create a new List that is the reverse the elements of the original List |
10 | Obtains the number of elements in this List. |
11 | Returns a sorted copy of the original List. |