Skip to content

Instantly share code, notes, and snippets.

@marrek13
Last active April 22, 2022 06:28
Show Gist options
  • Save marrek13/58b213a1542a356e3a177f4a70fc49f4 to your computer and use it in GitHub Desktop.
Save marrek13/58b213a1542a356e3a177f4a70fc49f4 to your computer and use it in GitHub Desktop.
Kotlin examples
fun main() {
//ARRAYS
val array = arrayOf(1,2,3,4,5,6)
// array size is just a property not another function
val arrayLength = array.size
// methods are chained and lambda function can be used
val multipliedArrayReversed = array.map { it * 2 }.reversed()
// the order of arguments is consistent
val oddsOnly = array.filter { it % 2 != 0 }
// STRINGS
val string = "Hello World"
// there are many helpful methods included comparing to Java
val onlySecondWord = string.substringAfter(' ')
// just another method to reverse the string
val reversedString = string.reversed()
// no need to remember about the arguments order
val startsWithHell = string.startsWith("Hell")
// again - no need to remember about the order
val containsHell = string.contains("Hell")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment