> For the complete documentation index, see [llms.txt](https://docs.b2winsuite.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.b2winsuite.com/5.2/scripting/data-types-and-data-structures/data-structures.md).

# Data Structures

syntax: <https://commons.apache.org/proper/commons-jexl/reference/syntax.html>

### Array Literal

An array is a fixed-size, contiguous memory structure that stores elements of the same type.

#### Syntax

> A `[` followed by zero or more expressions separated by `,` and ending with `]`, e.g. `[ 1, 2, "three" ]`
>
> This syntax creates an `Object[]`.
>
> Empty array literal can be specified as `[]` with result of creating `Object[]`
>
> JEXL will attempt to strongly type the array; if all entries are of the same class or if all entries are Number instance, the array literal will be an `MyClass[]` in the former case, a `Number[]` in the latter case.
>
> Furthermore, if all entries in the array literal are of the same class and that class has an equivalent primitive type, the array returned will be a primitive array. e.g. `[1, 2, 3]` will be interpreted as `int[]`.

#### Methods

* `size() -> Integer`: Returns the number of elements in the array.
* `get(index: Integer) -> T`: Retrieves the element at the specified `index` and returns it.
* `set(index: Integer, value: T)`: Sets the value of the element at the given `index`.

#### Usage

```typescript
var arr = Integer[]; // create an array of integers

arr = [1,2,3]; // set elements to array

arr.size(); // returns integer (3)
arr.get(1); // returns 2
arr.set(1, 4); // arr is now: [1, 4, 3]
```

***

### List Literal

A list is a dynamic array-like data structure that can grow or shrink and allows storage of elements of different types.

#### Syntax

> A `[` followed by zero or more expressions separated by `,` and ending with `,...]`, e.g. `[ 1, 2, "three",...]`
>
> This syntax creates an `ArrayList<Object>`.
>
> Empty list literal can be specified as `[...]`

#### Methods

* `add(value: T)`: Adds a new element with the provided value to the array.
* `remove(index: Integer)`: Removes the element at the specified `index`.
* `remove(value: T)`: Removes the first occurrence of the element with the specified `value`.
* `clear()`: Clears all elements from the array.
* `size(): Integer` Returns the number of elements in the list.
* `isEmpty():` Boolean Checks if the list is empty and returns `true` if it has no elements; otherwise, it returns `false`.
* `static of(): List<T>` Creates and returns an empty list.This class allows you to create and manage lists with elements of a specific data type.
* `contains(Object o): Boolean` - Returns boolean depending on whether list contains specified parameter.
* `toArray()` - convert List to Array Data Structure

#### Usage

```javascript
var list = [1, 2, "three",...] // creating a list, able to add and remove

list.add("four"); // now list is [1, 2, "three", "four"]

list.remove(2); // now list is [1,2]

list.contains(1); // returns true

list.clear(); // clears list
```

***

### Map Literal

A map  represented as `HashMap<Object, Object>`, is a collection that associates unique keys with corresponding values, facilitating efficient retrieval and modification of data based on key references.

{% hint style="info" %}
HashMaps are especially useful for defining a row in [SuiteTable](/5.2/scripting/data-types-and-data-structures/suitetable.md)
{% endhint %}

#### Syntax

> A `{` followed by zero or more sets of `key : value` pairs separated by `,` and ending with `}`, e.g. `{ "one" : 1, "two" : 2, "three" : 3, "more": "many more" }`
>
> This syntax creates a `HashMap<Object,Object>`.
>
> Empty map literal can be specified as `{:}`

#### Methods

* `create(); Map`

Creates an empty map and returns it.

* `add(Map<String, Object> map, String key, Object value): void`

adds a key-value pair to map. Returns nothing

* `size(); Integer`

Returns number of key-value pairs in map.

* `isEmpty: Boolean`

Returns true of map is empty, otherwise returns false.

* `cotainsKey(Object key): Boolean`

Returns true if map contains specified key, otherwise returns false.

* `containsValue(Object value): Boolean`

Returns true if map contains specified value, otherwise returns false.

* `remove(String key): Object`

Removes key from Map and returns the remove value object.

* `keySet(); and values();`

Return the keys and values of the map, respectively.

#### Usage

<pre class="language-javascript"><code class="lang-javascript"><strong>var map = MapUtil.create();
</strong>
MapUtil.add(map, "name", "steve");
MapUtil.add(map, "age", 40);
MapUtil.add(map, "birthday", LocalDate.now());

map.values(); // returns 2023-11-22,steve,40
map.keySet(); // returns birthday,name,age
map.remove("age"); // remove, age from map and returns 40

return map; 
</code></pre>

Or you can define map Manually:

```javascript
var map = {
    "name": "steve",
    "age": 40,
    "birthday": LocalDate.now()
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.b2winsuite.com/5.2/scripting/data-types-and-data-structures/data-structures.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
