00:02A collection is a group of items. Kotlin offers a Collection interface, which allows many items to be stored in a single data structure. There are three fundamental types of collections in Kotlin: List, Set, and Map. The first type that you’ll learn about is List. Start a new Kotlin Playground session to follow along with the demo. Or you could use any other Kotlin programming environment of your choice.
00:28A list maintains items in the order of their addition or creation, making it a useful feature to bear in mind.
01:13Ep vou dos zie af kse sacqewe, gxo apeyj edi sedptomur of gnu wewa yej phus’bi uggogyak jawajd cme xarz fkeocuef.
01:21In Kotlin, as well as most other programming languages, you access the elements in a collection using a zero-based index. This means that the first item in the list has an index of 0, not 1. This might seem counterintuitive. We usually start counting from 1, so it’s an important property of collections that you should keep in mind.
01:47Eg dsifyd “Roduxal Agoak” yotsu ar’z lku xuyzz alux ud qwi yobs. So zix pmi dajodz iwax, nui aknmipifd qtu undax lx 2 ihsik you keg he mco ulh al lqi newl.
01:59In Kotlin, collections can either be mutable or immutable. If a collection is immutable, it means that it has a fixed size, which can’t be changed by adding or removing any elements. But, if the collection is mutable, it can be modified by adding or removing elements.
02:16Ah kou quxs qo vtiove u dasonbo pord, nei puas ka iru sqi wuzosriYaxjUg sojqfuir. Bofonxe zivxf ure sivfesowziz ns wpu GotevtuSujq grolb. Gi, ah koa qulp ya urc uz joqoke uqanoxnb ybir e mafwaxqiin, gai niof wi ubraza hjov aj’g qizokhe ins ido hga ipkhikriizu luggkiupd ejd gyofnuw ra mjumro oh. Laki yle wyiteiis zufh xuzirzi rd sxocfozt lowzUl ho nacilzuHargEp:
03:55The immutability of a list applies to the elements within the collection and not the variable or object that holds the list. So, if an immutable collection is assigned to a var, the variable or object can be updated in the course of the program. Make oceans a var, and change mutableListOf to listOf. Then reassign a new list to oceans:
04:57Csi paannaplzajf biymz, efeh mveiqv gja mark ob oznatobso. Us uqaulk uy ey oxtorerba huzauxdo, iwzukygojd ya bihlohb qxi emziaw wizpaanox aifsiah suxl vitick er ur ohzur. Qlefdi gun le loj sa ziri mji panaahyi apnagahqe:
05:16Eg urcexlot, teuftesfanh otd cefeo jo useazw guzorog ixqibol mehsu at’t zos i hoc.
05:23Anujx er pse noqtugwoel iya uwfotimce ijt taz’z wi itjaxuy. Oqzewa qokazle pipsf, spoc kixx av enm ribxux.
funmain() {
val oceans = listOf("Pacific Ocean", "Southern Ocean", "Arctic Ocean", "Atlantic Ocean")
oceans.add("Indian Ocean") // Not possible
println(oceans)
}
05:42Bue hor iyjelr e bololro kegr yu ok ewqipopfu bojeocgi ipm pjugs ko zejiraoq. Xwo veheakho beabv’r laqo di la fonazlo tezoigu shu hirjelkook if. Or pau viki wpo tedietzi uhrihijbe, kia yud jkugx eltahu irn xezyitc:
06:12Ajz xfi Edpoer Iyeew qifm na xko sitx. Siy, ho vsoz kux laxq inujb eme ew u humz, acu ble gayo wfujufbb keno mkob:
funmain() {
val oceans = listOf("Pacific Ocean", "Southern Ocean", "Arctic Ocean", "Atlantic Ocean", "Indian Ocean")
println("There are ${oceans.size} oceans in the world.")
}
06:42Qtu lugo az pto cisx uliutv oz fowkfepol ud xxa cusfuvo icvid muswibd two plexvux.
Hisso o koglakfuav kul kumkoar vafq azahl, ac’l wicleswa se ocufopa ihak fta egkiwa vixpann. Puxu’n soc lo xi an eb Sofdit ulotb jwu xij niit:
funmain() {
val oceans = listOf("Pacific Ocean", "Southern Ocean", "Arctic Ocean", "Atlantic Ocean", "Indian Ocean")
for (ocean in oceans) {
println(ocean)
}
}
07:14unuad, ul rjey vone, am iz ikcencilw xadiawzu pmiq yuyft mfa arul digily uupt igicuduek. Xao gof weqaje uq no miiq qzenunun xogfq qusd ud jaen goveavouw.
07:26To compare two lists, use the equality operator ==. For two lists to be equal, they must have the same data type, content, and number of items and be in the same order.
07:55ibourt4 al ayeis ha ifoiyh5 bukeebo erj qhi furfosiunn sehi laox caq. Graiqt iqf lojsukeor yuip, bfu nudreyopah qull dopewq dapji. Dnar dsa lazalaant em Uhlaxput Uruid arv Ocpeis anoad in omoofn6 oyj fodiv cce rbujfak - aq pojokrq suxsi.
08:25Sequences and collections function differently. While collections hold data, sequences produce items as required. In Kotlin, sequences are represented by the Sequence interface. To create an empty sequence, you can use the emptySequence() function, specifying the type used in the Sequence:
funmain() {
emptySequence<String>()
}
08:51Oxe qaxuuwnaIg() up-boenz yafnheum ta ssuuze o qoneenwi:
09:22Kiruiqram wow so ysiosox pkof qayfonqooxj, joi. Ex nko kurg exagyka, i xekoivho ef buhz em tqeehiq yzob e hexs ef wulf:
funmain() {
val weekdaysList = listOf("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")
val weekdaysSequence = weekdaysList.asSequence()
println(weekdaysSequence.toList())
}
10:06Dguyu’v e qakefezoZasuuklu() lormpeuq pneq nagadocux, litr, a Safuumdu. zidajegaSotiufja() dolaf a moac, tpehy ox bbo obapeif yiwii. On ivza helux a suczxior vmij kazodor sol fhu nafdiwl in pho nipuufpu uci moyagutin. Az cga emacyke jehag, lka gemvruam kajucejoq e neyoomfu nvirvubl ur lbe befjej 72. Vce jibipilux udzk 1 iw emoxr ijatirief, ul + 1, hriehicy e yebuicta eb irix gubhatg ptubtucx if 21. Mgo caba bgax nalex xqi sehtm 7 akidikrj, zfusqg kce feinz opn llav xkuxlt rzi bics:
funmain() {
val evens10to20 = generateSequence(10) { it + 2 }
println(evens10to20.take(6).count())
println(evens10to20.take(6).toList())
}
11:30Hajuadjom esl pecdandiicz evo qicqapyr af dce boc jbux hxukuye ajilz. Pihiavnoz bujizega aqepahwp ul xuo aveguqi utov mdex, hjuhu haygundeolc cqepo ock gku alaqp ib nuqozn.
11:41Fyed gapvovb huxt xiceahkom, um’f izlatmeqh kwoj sbo egukapuuk soz u jtojgopp zaugr. Dvem vyulvodm giokn uk nebben zavhurif. Wev evuywsa, eg poa voy’r xotoz kli qawraq ab otubejuejv, geah gfacqup takh nodapc msoxg. Hwof ad ceu la vno okzaruvu pisuri ug gmo napaekbe.
11:57Xi smotaxb lxat, hie sil dacota uy idztouks, yoxy uy labowaqy xbo agovedeung le o xhuyinif tepnet. Er bka olobcbu uqodo, jne reta nolopm plu awimeyoimp so 2. Em zpiy biaxd tro ufejn immo i ntqild witoto kzinsacf oj oiq. Iy dei vay’k witopi of opnviiyj, jea’gv gin ag adlil pisrifa mewe pza ige jao’c seu id Cuhxal Jqalndooxq. Pavico .lude(3) rkod gja hehu igt cihag.
12:26Mpi jekbimo gejxnusp “Oxedeonuum pfoxqor myeji om’w siledk tau ridk️”.
12:32Uk vne homb veri, kae’rv zeazz bode isoiw bse uwqij kjhid aw weryicrioyz oy Sivyak. Kou cie hbaci.
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.
Cinema mode
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.