This article explores different ways to convert an IntArray to a String in Kotlin.

1. Using reduce() function

The idea is to map each element of the IntArray to a String and perform a reduction operation on elements using the reduce() function. This can be implemented as follows in Kotlin.

Download Code

Output:

1, 2, 3, 4, 5

2. Using contentToString() function

To print the string representation of the contents of an IntArray, use the contentToString() function. The string representation consists of all elements of the array enclosed within [] and the adjacent elements separated by ", ".

Download Code

Output:

[1, 2, 3, 4, 5]

 
To remove [ and ] from the string representation, use the replaceAll() function.

Download Code

Output:

1, 2, 3, 4, 5

3. Using Loop

The idea here is to create a new string and concatenate each array element to it, separated by ", ".

Download Code

Output:

1, 2, 3, 4, 5

That’s all about converting an IntArray to a String in Kotlin.