Kotlin Set plus()
Syntax & Examples


Syntax of Set.plus()

There are 4 variations for the syntax of Set.plus() extension function. They are:

1.
operator fun <T> Set<T>.plus(element: T): Set<T>

This extension function returns a set containing all elements of the original set and then the given element if it isn't already in this set.

2.
operator fun <T> Set<T>.plus(elements: Array<out T>): Set<T>

This extension function returns a set containing all elements of the original set and the given elements array, which aren't already in this set.

3.
operator fun <T> Set<T>.plus(elements: Iterable<T>): Set<T>

This extension function returns a set containing all elements of the original set and the given elements collection, which aren't already in this set. The returned set preserves the element iteration order of the original set.

4.
operator fun <T> Set<T>.plus(elements: Sequence<T>): Set<T>

This extension function returns a set containing all elements of the original set and the given elements sequence, which aren't already in this set.