반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Github
- numpy
- Google Spreadsheet
- Kotlin
- 파이썬
- Tkinter
- PySpark
- Mac
- dataframe
- SQL
- GIT
- Excel
- Google Excel
- google apps script
- Java
- gas
- matplotlib
- string
- django
- c#
- list
- Python
- hive
- PostgreSQL
- Apache
- Redshift
- math
- PANDAS
- array
Archives
- Today
- Total
달나라 노트
Kotlin - shuffled (collecion에 있는 요소들을 랜덤하게 재배열하기) 본문
728x90
반응형
shuffled 함수는 collection의 요소들을 랜덤하게 재배열합니다.
fun main() {
var fruits = listOf("Apple", "Strawberry", "Tomato", "Watermelon", "Grape")
fruits = fruits.shuffled()
println(fruits)
}
-- Result
[Strawberry, Tomato, Apple, Watermelon, Grape]
fruits라는 list를 생성하고 shuffled를 적용시켜보았습니다.
그 결과를 보면 fruits의 요소들이 랜덤하게 재정렬된 것을 볼 수 있습니다.
(따라서 이 결과는 위 코드를 실행할 때 마다 달라질 것입니다.)
728x90
반응형
'Kotlin' 카테고리의 다른 글
Kotlin - take (collecion에서 원하는 개수의 요소들만 얻기) (0) | 2021.04.13 |
---|---|
Kotlin - format (문자열 삽입하기) (0) | 2021.04.06 |
Kotlin - lateinit (initialize 미루기) (0) | 2021.03.19 |
Kotlin - super() (parent class의 method 그대로 쓰기) (0) | 2021.03.19 |
Kotlin - toString(), toInt(), toDouble(), toIntOrNull(), toDoubleOrNull() (Datatype의 변경) (0) | 2021.03.18 |
Comments