> For the complete documentation index, see [llms.txt](https://boxlang.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/stringbuilder/stringbuildernew.md).

# StringBuilderNew

Create a new StringBuilder instance or wrap an existing Java StringBuilder.

## Method Signature

```
StringBuilderNew(value=[any], capacity=[integer])
```

### Arguments

| Argument   | Type      | Required | Description                                                                                    | Default |
| ---------- | --------- | -------- | ---------------------------------------------------------------------------------------------- | ------- |
| `value`    | `any`     | `false`  | Optional initial value (String) or existing Java StringBuilder to wrap. Empty if not provided. |         |
| `capacity` | `integer` | `false`  | Optional initial capacity for newly created BoxStringBuilder instances.                        | `0`     |

## Examples

### Create a StringBuilder with stringBuilderNew()

Creates a new StringBuilder instance.

```java
result = stringBuilderNew();
writeOutput( result.toString() );
```

Result: (empty string)

### Create a seeded StringBuilder

```java
result = stringBuilderNew( 'hello' );
writeOutput( result.toString() );
```

Result: hello

### Create an empty StringBuilder with explicit capacity

```java
result = stringBuilderNew( capacity = 64 );
writeOutput( result.getBuffer().capacity() );
```

Result: at least 64

### Create a seeded StringBuilder with explicit capacity

```java
result = stringBuilderNew( 'hello', 64 );
writeOutput( result.toString() );
```

Result: hello

## Related

* [StringBuilderAppend](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuilderappend.md)
* [StringBuilderClear](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuilderclear.md)
* [StringBuilderContains](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuildercontains.md)
* [StringBuilderDelete](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuilderdelete.md)
* [StringBuilderEndsWith](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuilderendswith.md)
* [StringBuilderFind](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuilderfind.md)
* [StringBuilderInsert](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuilderinsert.md)
* [StringBuilderLeft](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuilderleft.md)
* [StringBuilderMid](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuildermid.md)
* [StringBuilderPrepend](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuilderprepend.md)
* [StringBuilderReplace](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuilderreplace.md)
* [StringBuilderReverse](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuilderreverse.md)
* [StringBuilderRight](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuilderright.md)
* [StringBuilderStartsWith](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuilderstartswith.md)
* [StringBuilderTrim](/boxlang-language/reference/built-in-functions/stringbuilder/stringbuildertrim.md)


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/stringbuilder/stringbuildernew.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
