This article explores different ways to check whether an array contains the specified value or not in Kotlin.

1. Using contains() function

The utility function to check the presence of an element in an array is with the contains() function.

Download Code

2. Using ‘In’ operator

Kotlin provides an In operator, which is an alternative syntax for contains.

Download Code

3. Using indexOf() function

Alternatively, you can use the indexOf() function as follows:

Download Code

4. Using any() function

Another plausible way is to use the any() function, which returns true if at least one element in the array matches the given predicate.

Download Code

5. Using filter() function

You can also use the filter() function to check if an array contains a specified value, as shown below:

Download Code

You can also perform a linear search on the given array to check for the specified value in the array.

Download Code

That’s all about determining whether an array contains a specific value in Kotlin.