Split String to Lines

To split string to lines in Kotlin programming, you may use String.lines() function. The function lines() : splits the char sequence to a list of lines delimited by any of the following character sequences: Carriage-Return Line-Feed, Line-Feed or Carriage-Return.

Syntax of String.lines() function

The function applied on a String returns List<String> containing lines.

Example to split string to lines

Following example demonstrates the usage of lines() function to split string to lines.

Conclusion :

In this Kotlin Tutorial, we have learnt to split a string to lines using String.lines() function.