---
schema_version: "1"
id: 49d8ff484c61e4360d153e15d3b25d85c52e6437a64015b3ca0ffaf92fd0e9ad
title: collapse
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dw-strings-functions-collapse.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dw-strings-functions-collapse
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f5dd3f85310b43efe825a1a79ff31a36e9d8f27ef964e0779f2921741888bc0f
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
---

# collapse

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## collapse(text: String): Array<String>

Collapses the string into substrings of equal characters.

Each substring contains a single character or identical characters that are adjacent to one another
in the input string. Empty spaces are treated as characters.

_Introduced in DataWeave version 2.4.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>text</code></p></td><td><p>The string to collapse.</p></td></tr></tbody></table>

### Example

This example shows how the function collapses characters. Notice that the empty space (" ") is
treated as a character.

#### Source

```DataWeave
%dw 2.0
import collapse from dw::core::Strings
output application/json
---
collapse("a  b babb a")
```

#### Output

```Json
["a", "  ", "b", " ", "b", "a", "bb", " ", "a"]
```

## collapse(text: Null): Null

Helper function that enables `collapse` to work with a `null` value.

_Introduced in DataWeave version 2.4.0._
