Published Nov 13, 2023
Contribute to Docs

.partition() takes a string parameter and returns two new strings. The first new string contains those characters that satisfy a supplied predicate, and the second new string contains those that do not satisfy that predicate.

A predicate takes an argument and returns a boolean true or false. If true is returned, the argument is said to satisfy the predicate. Otherwise, the argument does not satisfy the predicate.


  • xString: Supplies the string to be partitioned.
  • xPredicate: Supplies the predicate that partitions the value of xString.


The following example uses the character method .isUpperCase() as the predicate within .partition() to partition a string into uppercase letter characters and other characters:

fun main () {
val sampleString = "AbCd12/"

The above example results in the following output:

(AC, bd12/)

All contributors

Looking to contribute?

Learn Kotlin on Codecademy