[Kotlin] ๋ฆฌ์คํธ / ๋งต / ์งํฉ
ยท
๊ฐ๋ฐ ํ์์บก์/Kotlin
๋ฆฌ์คํธ ๋ฆฌ์คํธ๋ ๋ฐฐ์ด์ฒ๋ผ ๊ฐ์ ์๋ฃํ์ ๋ฐ์ดํฐ๋ค์ ์์๋๋ก ๊ฐ์ง๊ณ ์๋ ์๋ฃ๊ตฌ์กฐ์ด๋ค. ์์๋ฅผ ๋ณ๊ฒฝํ ์ ์๋ ์ฝ๊ธฐ ์ ์ฉ ๋ฆฌ์คํธ๋ listOf() ๋ฉ์๋๋ก ์์ฑํ ์ ์๋ค. val foods: List = listOf("๋ผ๋ฉด", "๊ฐ๋น", "๋๊ฐ์ค") //ํ ์ถ๋ก ์ผ๋ก ์๋ฃํ ์๋ต๊ฐ๋ฅ val foods = listOf("๋ผ๋ฉด", "๊ฐ๋น", "๋๊ฐ์ค") ์์๋ฅผ ๋ณ๊ฒฝํ๋ ๋ฆฌ์คํธ๋ฅผ ์์ฑํ ๋๋ mutableListOf() ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ค. val foods = mutableListOf("๋ผ๋ฉด", "๊ฐ๋น", "๋๊ฐ์ค") //ํ์คํ๋ฅผ ๋งจ ๋ค์ ์ถ๊ฐ foods.add("ํ์คํ") //๋งจ ์์ ์์ดํ
์ญ์ foods.removeAt(0) //1๋ฒ์งธ ์์ดํ
์ ๊ฐ์ํ์ผ๋ก ๋ณ๊ฒฝ foods[1] = "๊ฐ์ํ" println(..