> 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/list/listsort.md).

# ListSort

Sorts a delimited list and returns the result

## Method Signature

```
ListSort(list=[string], sortType=[any], sortOrder=[string], delimiter=[string], includeEmptyFields=[boolean], multiCharacterDelimiter=[boolean], localeSensitive=[boolean], callback=[any])
```

### Arguments

| Argument                  | Type      | Required | Description                                                                                               | Default |
| ------------------------- | --------- | -------- | --------------------------------------------------------------------------------------------------------- | ------- |
| `list`                    | `string`  | `true`   | The list to sort                                                                                          |         |
| `sortType`                | `any`     | `false`  | Options are text, numeric, or textnocase                                                                  |         |
| `sortOrder`               | `string`  | `false`  | Options are asc or desc                                                                                   | `asc`   |
| `delimiter`               | `string`  | `false`  | string the list delimiter                                                                                 | `,`     |
| `includeEmptyFields`      | `boolean` | `false`  | boolean whether to include empty fields in the returned result                                            | `false` |
| `multiCharacterDelimiter` | `boolean` | `false`  | boolean whether the delimiter is multi-character                                                          | `false` |
| `localeSensitive`         | `boolean` | `false`  | Sort based on local rules                                                                                 | `false` |
| `callback`                | `any`     | `false`  | Optional function to use for sorting - if the sort type is a closure, it will be recognized as a callback |         |

## Examples

### Simple example for listSort function

Uses the listSort() function to get the list which sorted by type text(case-sensitive)

[Run Example](https://try.boxlang.io/?code=eJzLySwuUbBVUHL293FxCw329PfTSc7PSUkrLc7Mz9NJTMlPStXxKU12ddUJcvT08Vey5irOLyrxgejKAVLBQK4GmKWjoBSSWlGiBKRTUouTlRQ0rbnKizJLUv1LSwpKgYrgOoESADo9JvA%3D)

```java
list = "BOXLANG,boxlang,adobe,Boxlang,RAILO";
sortList = listSort( list, "Text", "desc" );
writeOutput( sortList );

```

Result: boxlang,adobe,RAILO,Boxlang,BOXLANG

### Example for listSort function with delimiters

Uses the listSort() function with delimiters to get the list which sorted by type numeric

[Run Example](https://try.boxlang.io/?code=eJzLySwuUbBVUDI0sDYysNa1tLQ2MbM2NVCy5irOLyrxgcjmAKlgIFcDzNJRUPIrzU0tykxWAjITi8GUtZKCpjVXeVFmSap%2FaUlBKVAt3ACgBAAFZx6i)

```java
list = "10;20;-99;46;50";
sortList = listSort( list, "Numeric", "asc", ";" );
writeOutput( sortList );

```

Result: -99;10;20;46;50

### Simple Example for listSort function using sortType(textnocase)

Uses the listSort() function with delimiters to get the list which sorted by type textnocase(case-insensitive)

[Run Example](https://try.boxlang.io/?code=eJzLySwuUbBVUDI0qAlydampTPXxyS%2Bv0TUyMatJL0pNzavxD0rMS09VsuYqzi8q8YGozgFSwUCuBpilo6AUklpR4pfvnFicqgTkJRYng6gaJQVNa67yosySVP%2FSkoJSoHK4GUAJAMBvJ%2Bs%3D)

```java
list = "10|RED|yeLLow|-246|green|ORange";
sortList = listSort( list, "TextNoCase", "asc", "|" );
writeOutput( sortList );

```

Result: -246|10|green|ORange|RED|yeLLow

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJylkMsKwjAQRfd%2BxZCVwmiIWF34AB8IQtVF8QPadIRC20ge6OebWEVRBMFFkgvhzrl3ysLYnatIFxKmwAbYFUPso4iwG%2BEIhWDj1lkXlvbOnpxtQ%2BkNRum7ulsRWN0o5mVqJIMOdN6cbJLpWTjs4%2Bs5lM1zlRGXqsyPzhSq5rGTRFxEPJ4nYbqliw1vTuZG43%2By8MnCMrBC%2BRdWrWRq6OdenMOWqow0HF0trZ%2FaMlbHHhr2eyuDS09cN0QPwuSQbNBnWdBj2StXndrgfSFsL1xJk%2FhboCvvopB%2F)

```java
listNumeric = "4,-16,2,15,-5,7,11";
writeOutput( listsort( listNumeric, "numeric", "asc" ) );
writeOutput( "<br><br>" );
writeOutput( listsort( "Adobe/boxlang/Boxlang/15/LAS", "text", "desc", "/" ) );
writeOutput( "<br><br>" );
writeOutput( listsort( "Adobe,boxlang,boxlang,15,LAS", "textnocase", "asc" ) );
writeOutput( "<br><br>" );
// Member function
strList = "Boxlang,Boxlang,LAS,SUSI,AdoBe";
writeDump( strlist.listSort( "textnocase", "asc" ) );

```

## Related

* [GetToken](/boxlang-language/reference/built-in-functions/list/gettoken.md)
* [ListAppend](/boxlang-language/reference/built-in-functions/list/listappend.md)
* [ListAvg](/boxlang-language/reference/built-in-functions/list/listavg.md)
* [ListChangeDelims](/boxlang-language/reference/built-in-functions/list/listchangedelims.md)
* [ListCompact](/boxlang-language/reference/built-in-functions/list/listcompact.md)
* [ListContains](/boxlang-language/reference/built-in-functions/list/listcontains.md)
* [ListContainsNoCase](/boxlang-language/reference/built-in-functions/list/listcontainsnocase.md)
* [ListDeleteAt](/boxlang-language/reference/built-in-functions/list/listdeleteat.md)
* [ListEach](/boxlang-language/reference/built-in-functions/list/listeach.md)
* [ListEvery](/boxlang-language/reference/built-in-functions/list/listevery.md)
* [ListFilter](/boxlang-language/reference/built-in-functions/list/listfilter.md)
* [ListFind](/boxlang-language/reference/built-in-functions/list/listfind.md)
* [ListFindNoCase](/boxlang-language/reference/built-in-functions/list/listfindnocase.md)
* [ListFirst](/boxlang-language/reference/built-in-functions/list/listfirst.md)
* [ListGetAt](/boxlang-language/reference/built-in-functions/list/listgetat.md)
* [ListGetEndings](/boxlang-language/reference/built-in-functions/list/listgetendings.md)
* [ListIndexExists](/boxlang-language/reference/built-in-functions/list/listindexexists.md)
* [ListInsertAt](/boxlang-language/reference/built-in-functions/list/listinsertat.md)
* [ListItemTrim](/boxlang-language/reference/built-in-functions/list/listitemtrim.md)
* [ListLast](/boxlang-language/reference/built-in-functions/list/listlast.md)
* [ListLen](/boxlang-language/reference/built-in-functions/list/listlen.md)
* [ListMap](/boxlang-language/reference/built-in-functions/list/listmap.md)
* [ListNone](/boxlang-language/reference/built-in-functions/list/listnone.md)
* [ListPrepend](/boxlang-language/reference/built-in-functions/list/listprepend.md)
* [ListQualify](/boxlang-language/reference/built-in-functions/list/listqualify.md)
* [ListReduceRight](/boxlang-language/reference/built-in-functions/list/listreduceright.md)
* [ListRemoveDuplicates](/boxlang-language/reference/built-in-functions/list/listremoveduplicates.md)
* [ListRest](/boxlang-language/reference/built-in-functions/list/listrest.md)
* [ListSetAt](/boxlang-language/reference/built-in-functions/list/listsetat.md)
* [ListSome](/boxlang-language/reference/built-in-functions/list/listsome.md)
* [ListToArray](/boxlang-language/reference/built-in-functions/list/listtoarray.md)
* [ListTrim](/boxlang-language/reference/built-in-functions/list/listtrim.md)
* [ListValueCount](/boxlang-language/reference/built-in-functions/list/listvaluecount.md)
* [ListValueCountNoCase](/boxlang-language/reference/built-in-functions/list/listvaluecountnocase.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/list/listsort.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.
