apoc.coll.containsSorted

Function APOC Core

apoc.coll.containsSorted(coll, value) optimized contains on a sorted list operation (Collections.binarySearch) (returns single row or not)

Signature

apoc.coll.containsSorted(coll :: LIST? OF ANY?, value :: ANY?) :: (BOOLEAN?)

Input parameters

Name Type Default

coll

LIST? OF ANY?

null

value

ANY?

null

Usage Examples

The following checks if a sorted collection contains a value:

RETURN apoc.coll.containsSorted([1,4,5], 4) AS output;
Table 1. Results
Output

TRUE

This function will not work on unsorted collections, as shown in the example below:

RETURN apoc.coll.containsSorted([1,5,4], 4) AS output;
Table 2. Results
Output

FALSE

If we want to find a value in an unsorted collection, see apoc.coll.contains.