Suppose I have a set with elements. How to create List of the same elements? I see methiods asSequence
and asIterable
, but no asList
, why?
Asked
Active
Viewed 5,799 times
14

Dims
- 47,675
- 117
- 331
- 600
1 Answers
29
The function you're looking for is called toList()
:
val set: Set<Int> = setOf(1,2,3)
val list: List<Int> = set.toList()

Morgan Koh
- 2,297
- 24
- 24

s1m0nw1
- 76,759
- 17
- 167
- 196
-
Wow! Why is it sometimes "as" and sometimes "to"?! – Dims Mar 11 '18 at 21:42
-
11`as` most often implies that the object is being reused in the created instance. Take `asList` and `toList` for arrays as an example: https://stackoverflow.com/questions/48411392/how-are-kotlin-arrays-tolist-and-aslist-different/48411459#48411459 – s1m0nw1 Mar 11 '18 at 21:44