Swift Set shuffled()

The shuffled() method shuffles all the elements of a set.

Example


shuffled() Syntax

The syntax of the set shuffled() method is:

set.shuffled()

Here, set is an object of the set class.


shuffled() Parameters

The shuffled() method doesn't take any parameters.


shuffled() Return Value

The shuffled() method returns a shuffled array.


Example: Swift set shuffled()

Output

Original:  ["C", "Java", "Swift"]
Shuffled:  ["Swift", "Java", "C"]

Here, we have used the shuffled() method to shuffle the elements of the languages set.