반응형
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 |
Tags
- Java
- string
- google apps script
- PostgreSQL
- GIT
- 파이썬
- Python
- Google Excel
- gas
- Apache
- Redshift
- dataframe
- list
- Tkinter
- c#
- array
- django
- Google Spreadsheet
- math
- Github
- PySpark
- matplotlib
- PANDAS
- numpy
- hive
- Excel
- SQL
- Kotlin
- Mac
Archives
- Today
- Total
달나라 노트
Kotlin - take (collecion에서 원하는 개수의 요소들만 얻기) 본문
728x90
반응형
take 함수는 collection에서 원하는 개수의 요소만 골라 새로운 collection을 만듭니다.
fun main() {
var fruits = listOf("Apple", "Strawberry", "Tomato", "Watermelon", "Grape")
fruits = fruits.take(3)
println(fruits)
}
-- Result
[Apple, Strawberry, Tomato]
위 예시를 보면 fruits list에 take(3)이라는 함수를 적용하고 있습니다.
그 결과는 fruits list의 가장 앞의 3개 요소만 있는 list가 만들어졌음을 알 수 있죠.
728x90
반응형
'Kotlin' 카테고리의 다른 글
Kotlin - shuffled (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