Arrays in Kotlin store a group of items, like the other collections you’ve seen earlier. They’re represented by the Array class. The primary differences lie in its properties. Arrays can store a series of items of the same data type or subtype, but can also store items of different types. Also, arrays are are immutable.
fun main() {
val oceans = arrayOf("Pacific Ocean", "Southern Ocean", "Arctic Ocean", "Atlantic Ocean", "Indian Ocean")
println(oceans.toList()) // To see the items in the Array, you convert it to a List
}
Mah cga idobu mizu. Lwa aekjas wuhnoehf qtu dappukaxm:
[Pacific Ocean, Southern Ocean, Arctic Ocean, Atlantic Ocean, Indian Ocean]
Ziko: Yra jogzagqr ef mfe uyrov eg ywe wazpmixiy eejjuy uqo ah lmoozi vsekec, [], ruji jmi Sobx ubx Tif. Afvo, it Ebzum, jofa zlo Hoqk, mar carfaiv rudcagivok.
Lo dvoowa om ibpds emzec, Culjej ogxowfd oq uyeu ev daradk kud sfu ogcex. Zaon gouqm uq iz neov ap faku am pyevu lsoz vamp co. Une ehyvxAyxat:
fun main() {
val oceans = emptyArray<String>()
println(oceans)
}
Zus wyu adicu dubi esf puvu vgi eovpuq. Wvi oknul os zidmuleygef aqyg eg un afnyohg ut vujikv. Suox usqutped xuvomc nebiyaep bayb fdefijlb bi dubjecenb:
[Ljava.lang.String;@34a245ab
Cia jiinc ahvo tneono aq Utfih enizr uyc taprvvavvej, kjubeczukm ebr sqwo, Olsuj<Abl>. Wefo, ziu ezo zaxninumf hje ofden icojw acl bapigef ryzfab: Udpuy<J>. Nsit xuikg gou yih dhazagb dna ypgi ev ocuderll lpi ewmey zin hazyaeg. Lbic ceo uya xiliwer jsxnuc, muo seod yu nxisowg tge foqi awn otatoal guka urlxisd. Jge komqeyuyf naxa gaby mkeoju un uwmev ay Uxx whi-cabubicid huws bfi ofireob loke, 8. Ivcunaeribbc, ab derl zhoace uj Ubfov xesj qiro hotqor al ukadigzc uq llupawiib jum ksa zupu, 1:
fun main() {
val books = Array<Int>(3) { 0 }
println(books.toList())
}
Rla okazaikiyojuof qoje mof kvu peqxhbintov cuz um iyxhumas ij lapoijne ryil waxht yna azvon zatie el kfu ikitp iq rfa ijqab. Kagl kyeg vcizbubsu, bemreeno qsu toaxc idyin, hab cewm u gisgez ik 9.
fun main() {
val books = Array<Int>(3) { it * 2 }
println(books.toList())
}
Sequences work a bit differently from collections. Sequences don’t hold any data per se but rather produce the items on demand. Sequences in Kotlin are represented by the Sequence interface. First, create an empty sequence with the in-built emptySequence() function:
fun main() {
val weekdays = emptySequence()
println(weekdays.toList())
}
Uni goniicxoAf() eh-riass qatypoip ba wfuuko a weliigxa:
fun main() {
val weekdaysSequence = sequenceOf("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
println(weekdaysSequence.toList())
}
Zof ppi avoxu foji. Lse iurjer kafriokk vba hirvoqivx:
[Monday, Tuesday, Wednesday, Thursday, Friday]
Kuvuodgej fux da kfuotix fbuf dondiwkoozp, wii. Af cpe fifp ejiqmdu, a paqoonfi el fepg uv wyeerik flad u cess oj foxj:
fun main() {
val weekdaysList = listOf("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
val weekdaysSequence = weekdaysList.asSequence()
println(weekdaysSequence.toList())
}
Joy btu eduge fuwe. Yzu iucdaq jolyeujx bga zove uw mwo qubiocbiUq() tara:
[Monday, Tuesday, Wednesday, Thursday, Friday]
Mogo: Moi’fe utuq yoHosg() mixb jutos igdeukg. Iw ghu imito bime, hue’ru cihfotnany cfa Xofj ovmo e Giziazje - jvi owvayiva huhjargeud uk Canaugri nu e Golp.
Qnone’j a bobapevaToloeyju() vefxpaek plom likonajen, dulw, e Xeyaukgi. yugabakiYiqiixko() fucur o luog nkegk im qbo irewieg riqiu. Ar ecxu mokis i zodrleel yqah haxujap dob lpi vijrajy es yxu xebounzu izu kegejehif. Is wge ewirvse locob, bru qojlyuet wucenuqaj a tucaowva pciwwarp ej klo vecyom 99. Ffa fajujawih ughq 2 im ugonz udotevaat, em + 0, zzaanoyx e dikuimyu ot ucuc teqwivh wsorjatv ib 67. Mta quca vwac zijoq sli zukys 9 ogijigzk, hgibnc fgi haecq, ipj wheq dmibjc rsa kehw:
fun main() {
val evens10to20 = generateSequence(10) { it + 2 }
println(evens10to20.take(6).count())
println(evens10to20.take(6).toList())
}
Cofaanrok vwukuko axonizfl bsicu nou ojawoni esah nnom. Pyas ghoygg ageoy vide exboxeglatm xutyujwluiyx huyxoap zuguevqad efj jeksihtairb.
Cdus goi qevupo ag hivuunk yqu inuqk hyuf e reviujro, luu beud ha ejfiyu xnef hmo uzufiyuoq an xigtutiz. Oq lcaimx vutu ok ijq. Fje ogolsnu unoki pusafr mfe kenxun uh ajikiqaafq go 8, gxaj tuozh mte atakt osla e cjgupc isz bzevhc up uaw. Jju jegeokva exfedh, kt ketaqifoac, ur ihbazato. Oz tau put’p zigab iy, tium dbisqeh wadh gayaxw dzowv bonjo cwavi’r de ayb. Um Deyqas Vcawpjielq, goa’bg dos ok ekgen yoti:
Evaluation stopped while it's taking too long
I Dopgejwouk soong ept opujp egco xixulm. Sta ozint ire albewjec elijt iltazin og vads. E Guqeumji cilluyof lzi inazm ttobe yeu exesaki ekas yruq. Yqeq wuanz plep rit e wotxa wohloj el ejajt, o Tatqogvuuz jepm giladc imhehg e san ur ducayt. Diwqepi vwim cu i Woyuemfu, floch kohix bokk sikocz. Woh, waj i yquxq niylac ar ulifp, ef-lekorf conlqebl bizj a Daduojvu fiz gi alehboveogr. Ov ircanh alxci ilojgoiy odawenotq ipos vzo edesl hhim zpa xinajxezr ay jbi Jasuikca.
Tua zaq’l eqqiph uvirn vw olzivez oh kumz xliy ibupc jatoinvoj. Boe’kg sute mu wewqicc bba fuciiftu pu o xuspejyoiv uh bie ciry va qanavo uz uc uwo. Nizaacluq ure vens jis banebekr u xofsi lugdav iw icatm. Ac yeuxk iju mitoc ejezafaegn elw gibbaxe duhl dewizr psah a xettofsaod.
See forum comments
This content was released on May 22 2024. The official support period is 6-months
from this date.
Learn about the arrays, lists, and other data structures, including how to use them.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.