Set is different from Array. Array is ordered. By the way Set isn’t. Another different thing is Array can have same elements.
For example,
let ar1 = [1, 1, 1, 1]
The code above is possible in Array. But you can’t do it in Set.
Set could be similar to Dictionary. Because each element in Set must be unique like Dictionary’s key value. Set conforms Hashable protocol in order to have unique elements.
The different thing between Set and Dictionary is that Set doesn’t have Key value.
Let me organize everything above.
Collection Type | Ordered | Unique | Stores |
---|---|---|---|
Array | Yes | No | Elements |
Dictionary | No | Keys | Key-value pairs |
Set | No | Elements | Elements |
0 κ°μ λκΈ:
Post a Comment