# UTIL_List

**Class** · Group: `Utilities`

Learn it: [Utilities guide](/utilities-guide)

<div class="apex-member apex-class">

```apex
global inherited sharing class UTIL_List
```

Various list utilities for manipulating lists of objects and SObjects. This class provides methods for converting, transforming, sorting, and partitioning lists, as well as utility methods for checking emptiness and creating typed lists.

**Example**

```apex
Boolean empty = UTIL_List.isEmpty(records);
List<List<SObject>> batches = UTIL_List.partition(records, 200);
```

</div>

---

## Methods

| Method | Description |
|--------|-------------|
| global static [Boolean](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm) [isEmpty](#isempty)([List](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_list.htm)<[Object](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Object.htm)> items) | Checks if an object array is empty or null. |
| global static [Boolean](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm) [isNotEmpty](#isnotempty)([List](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_list.htm)<[Object](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Object.htm)> items) | Checks if an object array is not empty. |
| global static [List](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_list.htm)<[List](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_list.htm)<[Object](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Object.htm)>> [partition](#partition)([List](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_list.htm)<[Object](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Object.htm)> objects, [Integer](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_integer.htm) partitionSize) | Partitions a list into smaller lists of the specified size. |

### isEmpty

<div class="apex-member">

```apex
global static Boolean isEmpty(List<Object> items)
```

Checks if an object array is empty or null.

**Parameters**

| Parameter | Type | Description |
|-----------|------|-------------|
| `items` | [List](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_list.htm) | The array to check. |

**Returns** [Boolean](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm) — True if the array is null or empty, false otherwise.

**Example**

```apex
List<Object> emptyList = new List<Object>();
Boolean isEmpty = UTIL_List.isEmpty(emptyList);
// isEmpty is true
```

</div>

### isNotEmpty

<div class="apex-member">

```apex
global static Boolean isNotEmpty(List<Object> items)
```

Checks if an object array is not empty.

**Parameters**

| Parameter | Type | Description |
|-----------|------|-------------|
| `items` | [List](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_list.htm) | The array to check. |

**Returns** [Boolean](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_boolean.htm) — True if the array is not null and not empty, false otherwise.

**Example**

```apex
List<Object> numbers = new List<Object>{1, 2};
Boolean isNotEmpty = UTIL_List.isNotEmpty(numbers);
// isNotEmpty is true
```

</div>

### partition

<div class="apex-member">

```apex
global static List<List<Object>> partition(List<Object> objects, Integer partitionSize)
```

Partitions a list into smaller lists of the specified size.

**Parameters**

| Parameter | Type | Description |
|-----------|------|-------------|
| `objects` | [List](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_list.htm) | A list of objects |
| `partitionSize` | [Object](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Object.htm) | The maximum size of each sub-list |

**Returns** [Object](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Object.htm) — A list of sub-lists, each no larger than partitionSize

**Example**

```apex
List<List<Object>> batches = UTIL_List.partition(records, 200);
```

</div>
