Cov txheej txheem:

Daim ntawv qhia hauv Kotlin yog dab tsi?
Daim ntawv qhia hauv Kotlin yog dab tsi?

Video: Daim ntawv qhia hauv Kotlin yog dab tsi?

Video: Daim ntawv qhia hauv Kotlin yog dab tsi?
Video: Hmong song "Daim Ntawv Hauv Lub Fwj'' Dedication to Nalee 2024, Kaum ib hlis
Anonim

Kotlin daim ntawv qhia yog ib phau ntawv uas muaj khub ntawm cov khoom. Daim ntawv qhia tuav cov ntaub ntawv nyob rau hauv daim ntawv ntawm khub uas muaj tus yuam sij thiab tus nqi. Daim ntawv qhia yuam sij yog cim thiab cov daim ntawv qhia tuav tsuas yog ib tus nqi rau txhua tus yuam sij. Kotlin distinguishes ntawm immutable thiab mutable daim ntawv qhia.

Yog li ntawd, koj ua daim ntawv qhia ntawm Kotlin li cas?

Yuav ua li cas los tsim Maps hauv Kotlin siv 5 lub Hoobkas sib txawv

  1. mapOf - tsim ib daim ntawv qhia tsis hloov. Thawj thiab feem ntau tus qauv ntawm kev tsim daim ntawv qhia hauv Kotlin yog siv mapOf.
  2. mutableMapOf - tsim ib daim ntawv qhia mutable.
  3. sortedMapOf - tsim SortedMap.
  4. hashMapOf - tsim ib HashMap.
  5. linkedMapOf - tsim ib LinkedHashMap.

Qhov thib ob, MutableList yog dab tsi hauv Kotlin? Kotlin MutableList yog ib qho interface thiab generic sau ntawm cov ntsiab lus. Nws tau txais daim ntawv Collection class. Cov txheej txheem ntawm MutableList interface txhawb ob qho tib si nyeem thiab sau ua haujlwm. Thaum cov ntsiab lus hauv MutableList tau tshaj tawm tias, nws tuaj yeem ntxiv cov ntsiab lus hauv nws lossis tshem tawm, yog li nws tsis muaj qhov ntev ntev.

Kuj kom paub yog, dab tsi yog cia hauv Kotlin?

Kotlin ua yog ib txoj haujlwm scoping uas qhov sib txawv uas tau tshaj tawm hauv qhov kev qhia tsis tuaj yeem siv sab nraud. Ib qho piv txwv qhia kob let muaj nuj nqi yog muab hauv qab no.

Kuv yuav tsim ib qho arrayList hauv Kotlin li cas?

Kotlin ArrayList Piv txwv 1- khoob ArrayList

  1. lom zem main(args: Array){
  2. val arrayList = ArrayList() // Tsim ib qho arraylist khoob.
  3. arrayList.add("Ajay") // Ntxiv cov khoom hauv arraylist.
  4. arrayList.add("Vijay")
  5. arrayList.add("Prakash")
  6. arrayList.add("Rohan")
  7. arrayList.add("Vijay")

Pom zoo: