Collections Operations

Run Settings
LanguageKotlin
Language Version
Run Command
fun main(args : Array<String>){ //funFilter() //filterNot() //map() //count() // firstItem() // first()( //sum() sorted() } fun funFilter(){ val numberList = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) val evenList = numberList.filter{it % 2 == 0} print(evenList) } fun filterNot(){ val numberList = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) val notEvenList = numberList.filterNot{ it % 2 == 0 } print(notEvenList) } fun map(){ val numberList = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) val multipliedBy5 = numberList.map { it * 5 } println(multipliedBy5) } fun count(){ val numberList = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) //hitung jumlah println(numberList.count()) //hitung habis di bagi 3 print(numberList.count{ it % 3 == 0}) } fun firstItem(){ val numberList = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) //cari ganjil pertama val firstOddNumber = numberList.find{ it % 2 == 1 } println(firstOddNumber) } //firstOrNull() dan lastOrNull() fun first(){ val numberList = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) val habisdibagi3 = numberList.first { it % 3 == 0} print(habisdibagi3) } fun sorted(){ val kotlinChar = listOf('k', 'o', 't', 'l', 'i', 'n') //ascending val ascendingSort = kotlinChar.sorted() println(ascendingSort) //descending val descendingSort = kotlinChar.sortedDescending() println(descendingSort) } fun sum(){ val numberList = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) val total = numberList.sum() }
Editor Settings
Theme
Key bindings
Full width
Lines