You can use the filter
function to leave only those keywords contained in content
:
val match = keywords.filter { it in content }
Here match
is a List<String>
. If you want to get an array in the result, you can add .toTypedArray()
call.
in
operator in the expression it in content
is the same as content.contains(it)
.
If you want to have case insensitive match, you need to specify ignoreCase
parameter when calling contains
:
val match = keywords.filter { content.contains(it, ignoreCase = true) }