English
List
About 813 wordsAbout 3 min
2026-01-09
List
List - A collection type enclosed with [] and elements separated by commas.
Summary
Define a List: List list = []
Example:
List colors = ["red","blue","green","yellow"]
```text
List type methods:
- list.add(`<Object any_type>`): Adds an element to the list
Return type: Boolean
Example:
```text
List colors = ["red", "blue", "green"]
colors.add("yellow") //Returns: true
```text
- list.addAll(`<List list1>`): Adds multiple elements to the list
Return type: Boolean
Example:
```text
List colors = ["red", "blue"]
colors.addAll(["green", "yellow"]) //Returns: true
```text
- list.clear(): Clears the list
Return type: void
Example:
```text
List colors = ["red", "blue"]
colors.clear()
```text
- list.contains(`<Object any_type>`): Checks if the list contains the specified element. Returns "true" if the element exists
Return type: Boolean
Example:
```text
List colors = ["red", "blue", "green", "yellow"]
result = colors.contains("red") //Returns: true
```text
- list.containsAll(`<List list1>`): Checks if the list contains all specified elements. Returns "true" if all elements exist
Return type: Boolean
Example:
```text
List colors = ["red", "blue", "green"]
result = colors.containsAll(["red", "yellow"]) //Returns: false
```text
- list.indexOf(`<Object any_type>`): Returns the index of the given element in the list (first element index is "0")
Return type: int
Example:
```text
List colors = ["red", "blue", "green", "yellow"]
result = colors.indexOf("green") //Returns: 2- list.get(
<int indexNumber>): Returns the element at the specified position (first element index is "0") Return type: Object
Example:
List colors = ["red", "blue", "green", "yellow"]
result = colors.get(1) // Returns: "blue"- list.size(): Returns the number of elements in the list Return type: int
Example:
List colors = ["red", "blue", "green", "yellow"]
result = colors.size() //Returns: 4
```text
- list.sort(`<Boolean bool>`): Sorts the list. Optional boolean parameter specifies ascending (true)/descending (false) order, defaults to ascending when empty
Return type: List
Example:
```text
List colors = ["red", "blue", "green", "yellow"]
colors.sort() // Returns: ["blue","green","red","yellow"]
```text
- list.subList(`<int startIndex>`, `<int endIndex>`): Returns a sublist from the given list between the specified start (inclusive) and end (exclusive) indices
Return type: List
Example:
```text
List colors = ["red", "blue", "green", "yellow"]
result = colors.subList(1, 3); // Returns: ["blue","green"]
```text
- list.remove(`<int index>`): Removes and returns the element at the specified index (first element index is "0")
Return type: Object
Example:
```text
List colors = ["red", "blue", "green", "yellow"]
colors.remove(2) // Returns: "green"
```text
- list.isEmpty(): Checks if the list is empty. Returns true if the list contains no elements, false otherwise
Return type: Boolean
Example:
```text
List colors = ["red", "blue", "green", "yellow"]
result = colors.isEmpty() // Returns: false- list.intersect(
<List list>): Returns the intersection between the specified list and current list Return type: List
Example:
colors = ["red", "blue", "green", "orange"]
fruits = ["apple","orange","banana"]
result = colors.intersect(fruits) // Returns: ["orange"]- list.lastIndexOf(
<Object any_type>): Returns the index of the last occurrence of the specified element in the list Return type: BigDecimal
Example:
colors = ["red", "blue", "green", "yellow", "green"]
result = colors.lastIndexOf("green") //Returns: 4
```text
- list.eachWithIndex(`<Closure closure>`): Iterates through list elements with both item and index passed to the closure
Return type: List
Example:
```text
List list = ["a", "c"]
list.eachWithIndex { item, int i ->
log.info(item)
log.info(i)
} //Runtime log: a 0 b 1
```text
- list.each(`<Closure closure>`): Iterates through list elements with item passed to the closure
Return type: List
Example:
```text
List list = ["a", "c"]
list.each { item ->
log.info(item)
} //Runtime log: a b
```text
- list.any{`<Closure closure>`}: Checks if at least one element satisfies the condition
Return type: Boolean
Example 1:
```text
List list = ["a", "b"]
Boolean b = list.any { x -> x == "a" } // Checks if any element equals "a"
log.info(b)
// Runtime log: true
```text
Example 2:
```text
List list = [["a":1], ["a":2]]
Boolean b = list.any { x -> (x.a as Integer) > 1 } // Checks if any map element has value > 1 for key "a"
log.info(b)
// Runtime log: true
```text
- list.collect{`<Closure closure>`}: Collects values from each map element in the list
Return type: List
Example:
```text
List list = [["a":1], ["a":2]]
List result = list.collect { x -> x.a }
log.info(result)
// Runtime log: [1, 2]
```text
- list.find{`<Closure closure>`}: Finds the first map element in the list that satisfies the condition
Return type: Map
Example:
```text
List list = [["a":1], ["a":2]]
Map map = list.find { x -> (x.a as Integer) > 1 }
log.info(map)
// Runtime log: {a=2}
```text
## Changelog
| Version | Date | Changes | Author |
| --- | --- | --- | --- |
| v1.0 | 2026-05-20 | Initial version | |
## Background
This document provides detailed information about the List API functionality and usage, helping developers integrate relevant capabilities.
## Applicable Scenarios
Specific applicable scenarios are determined by actual business needs. Developers can select the appropriate API for integration as required.
## Prerequisites
- Access to Fxiaoke Open Platform
- Application authorization and configuration completed
- Basic knowledge of relevant business domain
## Steps
Please refer to the detailed instructions for each API.
## Notes
- Ensure prerequisites are met before calling APIs
- Pay attention to API call frequency limits
- Refer to error code documentation for exception handling
> **Compatibility:** This version currently has no deprecated or compatibility notes.