# ListFilter

Filters a delimted list and returns the values from the callback test This BIF will invoke the callback function for each entry in the list, passing the entry as a string.

* If the callback returns true, the entry will be included in the new list.
* If the callback returns false, the entry will be excluded from the new list.
* If the callback requires strict arguments, it will only receive the entry as a string.
* If the callback does not require strict arguments, it will receive the entry as a string, the index (0-based), and the original list as a string.

## Parallel Execution

If the `parallel` argument is set to true, and no `max_threads` are sent, the filter will be executed in parallel using a ForkJoinPool with parallel streams. If `max_threads` is specified, it will create a new ForkJoinPool with the specified number of threads to run the filter in parallel, and destroy it after the operation is complete. Please note that this may not be the most efficient way to filter, as it will create a new ForkJoinPool for each invocation of the BIF. You may want to consider using a shared ForkJoinPool for better performance.

## Method Signature

```
ListFilter(list=[string], filter=[function:Predicate], delimiter=[string], includeEmptyFields=[boolean], multiCharacterDelimiter=[boolean], parallel=[boolean], maxThreads=[any], virtual=[boolean])
```

### Arguments

| Argument                  | Type                 | Required | Description                                                                                                                                                                                                                                                                                     | Default |
| ------------------------- | -------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `list`                    | `string`             | `true`   | string list to filter entries from                                                                                                                                                                                                                                                              |         |
| `filter`                  | `function:Predicate` | `true`   | function closure filter test. You can alternatively pass a Java Predicate which will only receive the 1st arg.                                                                                                                                                                                  |         |
| `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` |
| `parallel`                | `boolean`            | `false`  | Whether to run the filter in parallel. Defaults to false. If true, the filter will be run in parallel using a ForkJoinPool.                                                                                                                                                                     | `false` |
| `maxThreads`              | `any`                | `false`  | <p>The maximum number of threads to use when running the filter in parallel. If not passed it will use the default number of threads for the ForkJoinPool.<br>If parallel is false, this argument is ignored. If a boolean is provided it will be assigned to the virtual argument instead.</p> |         |
| `virtual`                 | `boolean`            | `false`  | ( BoxLang only) If true, the function will be invoked using virtual threads. Defaults to false. Ignored if parallel is false.                                                                                                                                                                   | `false` |

## Examples

### Example using a simple numeric comparison

Take list and use List Filter to return items that are 3 and higher.

[Run Example](https://try.boxlang.io/?code=eJzLK81NSi3yySwuUbBVUDLUMdIx1jHRMdUxU7LmKskoSk31L%2FLNL0oFSuYA1bhl5pSkFmko5MF16ShoKDjmVSpklqTmKmgq2NopVHNxFqWWlBblQcTsbBWMrblqFTStucqLgCIppbkFGgrIRgNlAO%2BmKaI%3D)

```java
numberList = "1,2,3,4,5,6";
threeOrMore = listFilter( numberList, ( Any item ) => {
	return item >= 3;
} );
writedump( threeOrMore );

```

Result: A List with the values '3,4,5,6'

### Example using a member function

This is the same example as above, but using a member function on the list instead of a standalone function.

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

```java
numberList = "1,2,3,4,5,6";
threeOrMore = numberList.listFilter( ( Any item ) => {
	return item >= 3;
} );
writedump( threeOrMore );

```

Result: A List with the values '3,4,5,6'

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJyNj0FrwzAMhc%2Fxr9BySsGsPyB0MCi9FcYG29lb5dVgK0WRm5Wl%2F31yaNnWXnrUe096%2BtIhhl5gAfWL2%2BP45gR5fIqOZPxkRKpb40NU8Rn7HEuw5FeT1ECati008EgHwIgJSccyhM0XzGDxAN%2BmCr45m3CnVUNpqdVWr2KUzATCGVtTHc1Z8C72qhwt1KNmWzNwEFzmtGvg30tqzeewxvSODKtMHxI6MuWxVxcLWUdoZeisbJXI%2Bi6z9WGPisbYn4g0ev%2BX7JfohEObK5yJZTp6K8sFRqlX5QcTI3x6)

```java
mylist = "Save|Water|Plant|green";
filterResult = listFilter( mylist, ( Any element, Any idx ) => {
	if( element != "water" ) {
		return true;
	}
	return false;
}, "|" );
writeDump( filterResult );
// Member Function
listVal = "one,two,three,four,five";
res = listVal.listFilter( ( Any elem, Any ind ) => {
	if( elem != "three" ) {
		return true;
	}
	return false;
} );
writeDump( res );

```

## Related

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


---

# Agent Instructions: 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:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/list/listfilter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
