The * operator is known as the Spread Operator in Kotlin.

From the Kotlin Reference:

When you call a vararg-function, you can pass arguments individually, for example asList(1, 2, 3). if you already have an array and want to pass its contents to the function, use the spread operator (prefix the array with *):

It can be applied to an Array before passing it into a function that accepts vararg.

For Example...

If you have a function that accepts a varied number of arguments...

fun sumOfNumbers(vararg numbers: Int): Int {
    return numbers.sum()
}

Use the spread operator to pass an array's elements as the arguments:

val numbers = intArrayOf(2, 3, 4)
val sum = sumOfNumbers(*numbers)
println(sum) // Prints '9'

Notes:

  • The * operator is also the multiplication operator (of course).
  • The operator can only be used when passing arguments to a function. The result of the operation cannot be stored since it yields no value (it is purely syntactic sugar).
  • The operator may confuse some C/C++ programmers at first because it looks like a pointer is being de-referenced. It isn't; Kotlin has no notion of pointers.
  • The operator can be used in-between other arguments when calling a vararg-function. This is demonstrated in the example here.
  • The operator is similar to the apply function in various functional programming languages.
Answer from byxor on Stack Overflow
🌐
Baeldung
baeldung.com › home › kotlin › kotlin basics › varargs and spread operator in kotlin
Varargs and Spread Operator in Kotlin | Baeldung on Kotlin
April 28, 2026 - The “*” behind the numbers array variable is the spread operator. Under-the-hood, Kotlin translates its varargs to Java varargs.
Top answer
1 of 5
298

The * operator is known as the Spread Operator in Kotlin.

From the Kotlin Reference:

When you call a vararg-function, you can pass arguments individually, for example asList(1, 2, 3). if you already have an array and want to pass its contents to the function, use the spread operator (prefix the array with *):

It can be applied to an Array before passing it into a function that accepts vararg.

For Example...

If you have a function that accepts a varied number of arguments...

fun sumOfNumbers(vararg numbers: Int): Int {
    return numbers.sum()
}

Use the spread operator to pass an array's elements as the arguments:

val numbers = intArrayOf(2, 3, 4)
val sum = sumOfNumbers(*numbers)
println(sum) // Prints '9'

Notes:

  • The * operator is also the multiplication operator (of course).
  • The operator can only be used when passing arguments to a function. The result of the operation cannot be stored since it yields no value (it is purely syntactic sugar).
  • The operator may confuse some C/C++ programmers at first because it looks like a pointer is being de-referenced. It isn't; Kotlin has no notion of pointers.
  • The operator can be used in-between other arguments when calling a vararg-function. This is demonstrated in the example here.
  • The operator is similar to the apply function in various functional programming languages.
2 of 5
39

In addition to the answers that were directly towards "what is this thing!?!", you often have the case where you have a List and want to pass it to a function that is expecting a vararg. For this, the conversion is:

someFunc(x, y, *myList.toTypedArray())

Assuming that last parameter of someFunc is vararg of the same type as the elements in the list.

Discussions

Help me understand the spread operator

Spread operator in Python and Kotlin are really much different things. Python lets you pass any positional arguments using an array. Kotlin lets you only pass vararg arguments.

And the reason why only arrays are supported is because vararg is internally represented as just array. So * in Kotlin does not really unpack anything. Actually, it is the opposite. If you declare a function with vararg then passed arguments are packed into an array. By using * you can pass an array directly.

More on reddit.com
🌐 r/Kotlin
10
21
July 26, 2021
Spread-object operator missing in kotlin? - Language Design - Kotlin Discussions
I was wondering if there is something like the spread-object operator found in Javascript/Typescript? I am aware that there is a spread function arguments operator. The spread object operator allows one to pass-on attribute values of objects of shared types without constructors. More on discuss.kotlinlang.org
🌐 discuss.kotlinlang.org
1
June 1, 2018
Operator overload spread operator - Language Design - Kotlin Discussions
Just a question. Is there a reason that the spread-operator is not overridable? Or that it is only added to arrays? More on discuss.kotlinlang.org
🌐 discuss.kotlinlang.org
0
October 29, 2018
How often do you use the spread operator "*" ?
I use it when I have a naturally List or Array type that I need to use with a function that accepts a varargs of the same type. Syntactic sugar really. It's cool for showing off to Java developers. 🤣 More on reddit.com
🌐 r/Kotlin
9
7
January 7, 2021
People also ask

What does 'vararg' do in Kotlin?
The vararg keyword in Kotlin is used to define a function parameter that can accept a variable number of arguments. When a function has a vararg parameter, you can pass any number of values (zero or more) to that function, and those values are treated as an array within the function body. This provides a flexible way to handle function calls with a dynamic number of arguments.
🌐
dhiwise.com
dhiwise.com › post › the-kotlin-spread-operator-unfolding-arrays-into-arguments
Maximizing Efficiency with the Kotlin Spread Operator
How to pass array to varargs in Kotlin?
To pass an array to a function that accepts vararg parameters in Kotlin, you need to use the Kotlin spread operator, which is the asterisk *. By prefixing the array with the spread operator when making the function call, the array is expanded into individual elements, allowing Kotlin to interpret them as separate arguments. Example: ```kotlin fun printVarargs(vararg numbers: Int) { numbers.forEach { print("$it ") } } fun main() { val intArray = intArrayOf(1, 2, 3) printVarargs(*intArray) } ``` In the above example, *intArray uses the spread operator to pass the array elements i
🌐
dhiwise.com
dhiwise.com › post › the-kotlin-spread-operator-unfolding-arrays-into-arguments
Maximizing Efficiency with the Kotlin Spread Operator
How many varargs can we have in a function in Kotlin?
In Kotlin, a function can have only one vararg parameter, and it must be the last parameter if the function has other parameters. This restriction ensures that the compiler can clearly distinguish between the vararg values and the other arguments.
🌐
dhiwise.com
dhiwise.com › post › the-kotlin-spread-operator-unfolding-arrays-into-arguments
Maximizing Efficiency with the Kotlin Spread Operator
🌐
DhiWise
dhiwise.com › post › the-kotlin-spread-operator-unfolding-arrays-into-arguments
Maximizing Efficiency with the Kotlin Spread Operator
June 6, 2024 - If you have additional parameters ... operator is used in a function call, the compiler unwraps each element from the array and passes them into the function body as separate parameters....
🌐
Reddit
reddit.com › r/kotlin › help me understand the spread operator
r/Kotlin on Reddit: Help me understand the spread operator
July 26, 2021 -

Hey all,

Been learning Kotlin (my background is Python)!
I was pretty happy to see that Kotlin has a very similar operation to unpack a collection of items (*).

That being said, I couldn't really find the exact reason why the spread operator only supports Arrays and not other types of collections like Lists? From my understanding, the main difference between List and and arrays is that Arrays are mutable whereas Lists are not by default (you'd have to call a mutableListOf), and arrays are fixed in size.

Where does this limitation come from?

🌐
Medium
proandroiddev.com › kotlins-vararg-and-spread-operator-4200c07d65e1
Kotlin’s vararg and spread operator | by Tibi Csabai | ProAndroidDev
January 27, 2019 - Kotlin has pointers?” was my ... not a pointer. It’s Kotlin’s spread operator — the operator that unpacks an array into the list of values from the array....
🌐
Kotlin
kotlinlang.org › docs › functions.html
Functions | Kotlin Documentation
When you call a vararg-function, you can pass arguments individually, as in the example of asList(1, 2, 3). If you already have an array and want to pass its contents to a function as a vararg parameter or as a part of it, use the spread operator by prefixing the array name with *:
Find elsewhere
🌐
Hoennig
michael.hoennig.de › blog › 2019 › 2019-07-13-an-object-spread-operator-for-kotlin.html
Michael Hönnig - An Object Spread Operator for Kotlin
The first approach to implement an object spread operator with Kotlin is based on classes which store their properties in a Map.
🌐
Kotlin Discussions
discuss.kotlinlang.org › language design
Spread-object operator missing in kotlin? - Language Design - Kotlin Discussions
June 1, 2018 - I was wondering if there is something ... arguments operator. The spread object operator allows one to pass-on attribute values of objects of shared types without constructors....
🌐
Kotlin Discussions
discuss.kotlinlang.org › language design
Operator overload spread operator - Language Design - Kotlin Discussions
October 29, 2018 - Just a question. Is there a reason that the spread-operator is not overridable? Or that it is only added to arrays?
🌐
Delft Stack
delftstack.com › home › howto › kotlin › kotlin spread operator
Kotlin Spread Operator | Delft Stack
August 19, 2022 - The spread operator is used to pass multiple arguments in places where more than one argument is expected. In Kotlin, the spread operator can be used with function parameters prefixed with the vararg keyword.
🌐
Commonsware
klassbook.commonsware.com › lessons › Collections › spread-operator.html
Klassbook: Spread Operator - CommonsWare
If you already have an array that contains the values that you would want to pass to a vararg function, you can use the "spread operator" (*) as a prefix to the array. Then, instead of treating the array as a single "vararg", Kotlin will expand the array and consider each of its members to ...
🌐
Medium
medium.com › @madananand › programming-kotlin-use-of-spread-operator-a620190d5f33
[Programming] Kotlin Use of Spread operator - Madan Anand - Medium
August 25, 2022 - [Programming] Kotlin Use of Spread operator Spread Operator “*” are the operator that unpacks an array into the list of values from the array. Mainly I used it for output operations. Because of …
🌐
Appmarq
appmarq.com › public › security,1030022,Avoid-passing-an-existing-array-with-spread-operator-as-an-argument-using-vararg-as-parameters-Kotlin
Avoid passing an existing array with spread operator as ...
Rule Definition In most cases using a spread operator causes a full copy of the array to be created before calling a method. This has a very high performance penalty. The decrease in performance in Kotlin as compared to Java is double in such case.
🌐
Kotlin Discussions
discuss.kotlinlang.org › language design
Allocation of vararge with spread operator - Language Design - Kotlin Discussions
October 6, 2016 - I used an Android game framework which had a vararge method. I called this method every frame. override fun update(){ foo(a,b,c) } I knew I don’t need a allocation here. So I fixed it with spread operator like I used to do in Java. val bar=arrayOf(a,b,c) //as a property override fun update(){ ...
🌐
DhiWise
dhiwise.com › post › how-to-convert-kotlin-list-to-vararg-step-by-step-guide
How to Convert Kotlin List to Vararg: A Comprehensive Guide
December 26, 2024 - Within the function body, vararg parameters are treated as arrays, allowing you to access and iterate over the array elements. The spread operator (*) is used to pass a Kotlin list to a vararg parameter.
🌐
Kotlin Discussions
discuss.kotlinlang.org › t › hidden-allocations-when-using-vararg-and-spread-operator › 1640
Hidden allocations when using vararg and spread operator - Kotlin Discussions
May 1, 2016 - As I understand it, if I pass arguments to a vararg function like so: function("a", "b", "c", "d") a new Array will be created to hold them. But what about this: val someStringArray<String> = ... function(*someStringA…
🌐
Medium
mujeebkhan1831.medium.com › take-a-look-on-some-unknown-kotlin-operators-eb928cf32172
Take a look on some 💎unknown Kotlin Operators | by Mujeeb ur rahman khan | Medium
June 30, 2023 - Let’s dive into the realm of ... let’s have a look on spread operator. The spread operator is used to unpack an array or list into individual elements....
🌐
Klocwork
help.klocwork.com › 2024 › en-us › reference › kt.spread_operator.htm
KT.SPREAD_OPERATOR | Klocwork 2024.4
In most cases using a spread operator causes a full copy of the array to be created before calling a method. This has a very high performance penalty. Benchmarks showing this performance penalty can be seen here: https://sites.google.com/a/athaydes.com/renato-athaydes/posts/kotlinshiddencosts-be...