Programming/Kotlin

[Kotlin] ์ฝ”ํ‹€๋ฆฐ ๋ฆฌ์ŠคํŠธ list ํŠน์ • ํ•„๋“œ๋กœ ๋‚ด๋ฆผ์ฐจ์ˆœ(DESC) ์ •๋ ฌํ•˜๋Š” ๋ฐฉ๋ฒ•

yuri lee 2023. 1. 20. 22:42
๋ฐ˜์‘ํ˜•

Intro

์•ˆ๋…•ํ•˜์„ธ์š”. ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ์ฝ”ํ‹€๋ฆฐ์—์„œ ๋‚ด๋ฆผ์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. 

 

How to do 

์ฝ”ํ‹€๋ฆฐ ๋‚ด์žฅ ํ•จ์ˆ˜์ธ sortedByDescending ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋˜๋Š”๋ฐ์š”, ๋‚ด๋ฆผ์ฐจ์ˆœ์— ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ํŠน์ • ํ•„๋“œ ๊ฐ’์„ ๋„ฃ์–ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. 

result.sortedByDescending { it.date }

https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/sorted-by-descending.html

๋ฐ˜์‘ํ˜•