> 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/set/setnew.md).

# SetNew

Create a new empty Set, optionally pre-seeded from an existing collection.

The backing variant (hash, linked, or sorted) and case-sensitivity can be configured. When no seed is provided, an empty Set of the requested variant is returned.

## Method Signature

```
SetNew(type=[string], values=[any], caseSensitive=[boolean], isSynchronized=[boolean])
```

### Arguments

| Argument         | Type      | Required | Description                                                                                                                                                                               | Default   |
| ---------------- | --------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
| `type`           | `string`  | `false`  | <p>The backing variant: "default" / "hash" (HashSet), "linked" / "ordered" (LinkedHashSet,<br>preserves insertion order), or "sorted" / "tree" (TreeSet, natural ordering).</p>           | `default` |
| `values`         | `any`     | `false`  | <p>An optional seed collection (Array, Set, or anything castable to a Set). Its elements are<br>deduplicated into the new set. A single non-collection value seeds a one-element set.</p> |           |
| `caseSensitive`  | `boolean` | `false`  | Whether string element comparisons are case-sensitive. Defaults to false.                                                                                                                 | `false`   |
| `isSynchronized` | `boolean` | `false`  | Whether the set should be thread-safe (synchronized). Default is true.                                                                                                                    | `true`    |

## Examples

### Create an empty default Set

Creates a new empty hash-based Set (no ordering, fastest lookup).

```java
s = setNew();
writeOutput( s.size() );

```

Result: 0

### Create a linked (insertion-ordered) Set seeded with values

Duplicate values are automatically removed.

```java
s = setNew( type="linked", values=[ "c", "a", "b", "a" ] );
writeOutput( s.toArray().toString() );

```

Result: \[c, a, b]

### Create a sorted Set

Elements are kept in natural ascending order at all times.

```java
s = setNew( type="sorted", values=[ 9, 1, 5, 3 ] );
writeOutput( s.toArray().toString() );

```

Result: \[1, 3, 5, 9]

### Create a case-sensitive Set

By default Sets are case-insensitive. Pass `caseSensitive=true` to treat different cases as distinct elements.

```java
s = setNew( values=[ "Hello", "hello", "HELLO" ], caseSensitive=true );
writeOutput( s.size() );

```

Result: 3

### Default behavior is case-insensitive

```java
s = setNew( values=[ "Hello", "hello", "HELLO" ] );
writeOutput( s.size() );

```

Result: 1

### Create an unsynchronized (non-thread-safe) Set

Pass `isSynchronized=false` for a faster single-threaded set that skips locking overhead.

```java
s = setNew( isSynchronized=false, values=[ 1, 2, 3 ] );
writeOutput( s.size() );

```

Result: 3

## Related

* [BoxSetAdd](/boxlang-language/reference/built-in-functions/set/boxsetadd.md)
* [BoxSetAddAll](/boxlang-language/reference/built-in-functions/set/boxsetaddall.md)
* [BoxSetClear](/boxlang-language/reference/built-in-functions/set/boxsetclear.md)
* [BoxSetContains](/boxlang-language/reference/built-in-functions/set/boxsetcontains.md)
* [BoxSetContainsAll](/boxlang-language/reference/built-in-functions/set/boxsetcontainsall.md)
* [BoxSetDifference](/boxlang-language/reference/built-in-functions/set/boxsetdifference.md)
* [BoxSetEach](/boxlang-language/reference/built-in-functions/set/boxseteach.md)
* [BoxSetEquals](/boxlang-language/reference/built-in-functions/set/boxsetequals.md)
* [BoxSetEvery](/boxlang-language/reference/built-in-functions/set/boxsetevery.md)
* [BoxSetFilter](/boxlang-language/reference/built-in-functions/set/boxsetfilter.md)
* [BoxSetFind](/boxlang-language/reference/built-in-functions/set/boxsetfind.md)
* [BoxSetIntersection](/boxlang-language/reference/built-in-functions/set/boxsetintersection.md)
* [BoxSetIsDisjointFrom](/boxlang-language/reference/built-in-functions/set/boxsetisdisjointfrom.md)
* [BoxSetIsEmpty](/boxlang-language/reference/built-in-functions/set/boxsetisempty.md)
* [BoxSetIsSubsetOf](/boxlang-language/reference/built-in-functions/set/boxsetissubsetof.md)
* [BoxSetIsSupersetOf](/boxlang-language/reference/built-in-functions/set/boxsetissupersetof.md)
* [BoxSetMap](/boxlang-language/reference/built-in-functions/set/boxsetmap.md)
* [BoxSetNone](/boxlang-language/reference/built-in-functions/set/boxsetnone.md)
* [BoxSetReduce](/boxlang-language/reference/built-in-functions/set/boxsetreduce.md)
* [BoxSetReject](/boxlang-language/reference/built-in-functions/set/boxsetreject.md)
* [BoxSetRemove](/boxlang-language/reference/built-in-functions/set/boxsetremove.md)
* [BoxSetRemoveAll](/boxlang-language/reference/built-in-functions/set/boxsetremoveall.md)
* [BoxSetRetainAll](/boxlang-language/reference/built-in-functions/set/boxsetretainall.md)
* [BoxSetSome](/boxlang-language/reference/built-in-functions/set/boxsetsome.md)
* [BoxSetSymmetricDifference](/boxlang-language/reference/built-in-functions/set/boxsetsymmetricdifference.md)
* [BoxSetToArray](/boxlang-language/reference/built-in-functions/set/boxsettoarray.md)
* [BoxSetToList](/boxlang-language/reference/built-in-functions/set/boxsettolist.md)
* [BoxSetUnion](/boxlang-language/reference/built-in-functions/set/boxsetunion.md)
* [ObjectToSet](/boxlang-language/reference/built-in-functions/set/objecttoset.md)
* [SetOf](/boxlang-language/reference/built-in-functions/set/setof.md)
* [StructKeySet](/boxlang-language/reference/built-in-functions/set/structkeyset.md)
* [StructValueSet](/boxlang-language/reference/built-in-functions/set/structvalueset.md)
* [ToSet](/boxlang-language/reference/built-in-functions/set/toset.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 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://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/set/setnew.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.
