Quick actions

cmd+k|ctrl+k

Navigation

Languages

Collections Operations

Snippet info

Language

Kotlin

Visibility

public

Author

habib17

Created

2019-11-01T12:52:43Z

Updated

2019-11-01T13:00:47Z

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()
}



    
INFO