losanutrition.blogg.se

Kotlin list
Kotlin list













kotlin list

Kotlin - Convert list of characters to string.Kotlin - Convert string to list of characters.Kotlin - Split string by one or more spaces.Kotlin - Split string by any whitespace character.Kotlin - Trim white spaces around string.Kotlin - Remove last N haracters from string.Kotlin - Remove first N characters from string.Kotlin - Get random character from string.Kotlin - Count number of words in string.Kotlin - Check is string matches regular expression.Kotlin - Check if string ends with specific character.Kotlin - Check if string ends with specific suffix.Kotlin - Check if string starts with specific character.Kotlin - Check if string starts with specific prefix.Kotlin - Check if string contains specific character.Kotlin - Check if string contains specific substring.Kotlin - Check if strings are equal ignoring case.So, it explains how the reassignment happens.įurther, let’s look at the implementation of List‘s ‘ +‘ ( plus operation) operator: public operator fun Collection. Now, let’s take a closer look at this compilation error. First, as the List interface and its super types don’t have the plusAssign() function, here, myList += “Tom Cruise” is the same as myList = myList + “Tom Cruise”. However, the error message is different this time: “ Kotlin: Val cannot be reassigned.” Next, let’s test the += operator: val myList = listOf("Tom Hanks", "Brad Pitt")Īs we’ve expected, the code doesn’t compile either. If we compile the code above, the compiler complains: “Kotlin: Unresolved reference: add.” This is expected, as the List interface doesn’t have the add() method. But let’s create a test to verify if it’s true: var myList = listOf("Tom Hanks", "Brad Pitt") Since List is read-only, we can’t add an element to it. Finally, let’s look at the List type in Kotlin.















Kotlin list