![]() |
A set is a generic unordered collection that is used to store values of the same type. It means you are not allowed to keep different types in the set or we can say that a string type of set can only store string data types, not int type. You can use a set instead of an array if the order of the values is not defined or you want to store unique values. It doesn’t keep duplicate values, it always keeps unique values in it. It generally uses a hash table to store the elements. A set can be mutable or immutable. In Set, we can remove all the values from the set using the removeAll() function. This function is used to remove all the values from the specified set. It does not take any parameters. Syntax:
Return Value: It will remove all the elements from the specified set. Example 1: Swift
Output: Original Set: ["Rahul", "Mira", "Pihu", "Sumit", "Punit"] Final Set: [] Example 2: Swift
Output: Original Set: [2, 65, 458, 8, 76, 982, 3, 5, 4] Total number of elements in the AuthorRating set: 0 |
Reffered: https://www.geeksforgeeks.org
Swift |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |