Swift Set removeFirst()

The removeFirst() method removes the first element from the set.

Example


removeFirst() Syntax

The syntax of the set removeFirst() method is:

set.removeFirst()

Here, set is an object of the Set class.


removeFirst() Parameter

The removeFirst() method doesn't take any parameter.


removeFirst() Return Value

The removeFirst() returns the removed element from the set

Note: Since Sets are unordered collections, the random element is removed and returned.


Example: Swift Set removeFirst()

Output

Spain
["Greece", "Nepal"]

Here, we have used the removeFirst() method to remove the first element from the country set.

After removing the first element, we have printed the modified set.