Kotlin Kandy: Get A Random Element From A Collection
A blog by @mrhaki

Kotlin has very useful extensions functions for working with collections. These extension functions make working with collections more easy and fun. One of the extension functions is the random function. When you call random() Kotlin returns a single element from the collection using the default random source. The function also accepts a Random instance as...

#dev #softwaredevelopment #KotlinKandy

https://jdriven.com/blog/2026/05/Kotlin-Kandy-Get-A-Random-Element-From-A-Collection/

Kotlin Kandy: Get A Random Element From A Collection

Kotlin has very useful extensions functions for working with collections. These extension functions make working with collections more easy and fun. One of the extension functions is the random functi

JDriven Blog

Kotlin Kandy: Transform Map Keys Or Values With mapKeys And mapValues
A blog by @mrhaki

Sometimes you want to transform only the keys in a Map, or only transform the values. Kotlin has two useful methods to achieve this: mapKeys and mapValues. You can use mapKeys to transform the keys of the map while keeping the values the same. With mapValues you can transform the values of the map while keeping the keys the same. Both...

#dev #softwaredevelopment #KotlinKandy

https://jdriven.com/blog/2026/05/Kotlin-Kandy-Transform-Map-Keys-Or-Values-With-mapKeys-And-mapValues/

Kotlin Kandy: Transform Map Keys Or Values With mapKeys And mapValues

Sometimes you want to transform only the keys in a Map, or only transform the values. Kotlin has two useful methods to achieve this: mapKeys and mapValues. You can use mapKeys to transform the keys of

JDriven Blog
New post JDriven blog: Kotlin Kandy: Create Fix Sized Sublists From Iterables With chunked #Kotlin #KotlinKandy https://blog.jdriven.com/2022/12/Kotlin-Kandy-Create-Fix-Sized-Sublists-From-Iterables-With-chunked/
Kotlin Kandy: Create Fix Sized Sublists From Iterables With chunked

The chunked extension method is added to the Iterable Java class and makes it possible to split an interable into fixed sized lists. We define the size of the lists as argument to the chunked method.

JDriven Blog
New post JDriven blog: Kotlin Kandy: Split Collection Or String With Partition #Kotlin #KotlinKandy https://blog.jdriven.com/2022/12/Kotlin-Kandy-Split-Collection-Or-String-With-Partition/
Kotlin Kandy: Split Collection Or String With Partition

The method partition is available in Kotlin for arrays and iterable objects to split it into two lists. We pass a predicate lambda function to the partition method. The predicate should return either

JDriven Blog
New post JDriven blog: Kotlin Kandy: Taking Or Dropping Characters From A String #Kotlin #KotlinKandy https://blog.jdriven.com/2022/12/Kotlin-Kandy-Taking-Or-Dropping-Characters-From-A-String/
Kotlin Kandy: Taking Or Dropping Characters From A String

Kotlin adds a lot of extension methods to the String class. For example we can use the take method to get a certain number of characters from the start of a string value. With the drop method where we

JDriven Blog
New post JDriven blog: Kotlin Kandy: Find Common Prefix Or Suffix In Strings #Kotlin #KotlinKandy https://blog.jdriven.com/2022/12/Kotlin-Kandy-Find-Common-Prefix-Or-Suffix-In-Strings/
Kotlin Kandy: Find Common Prefix Or Suffix In Strings

If we want to find the longest shared prefix or suffix for two string values we can use the String extension methods commonPrefixWith and commonSuffixWith. The result is the prefix or suffix value tha

JDriven Blog
New post JDriven blog: Kotlin Kandy: Transform Items In A Collection To A Map With associate #Kotlin #KotlinKandy https://blog.jdriven.com/2022/12/Kotlin-Kandy-Transform-Items-In-A-Collection-To-A-Map-With-associate/
Kotlin Kandy: Transform Items In A Collection To A Map With associate

Kotlin gives us the associate method for collection objects, like lists, iterables and arrays. With this method we can convert the items in the collection to a new Map instance. The associate method a

JDriven Blog
Kotlin Kandy: Create Fix Sized Sublists From Iterables With chunked https://blog.mrhaki.com/2022/12/kotlin-kandy-create-fix-sized-sublists.html #kotlin #KotlinKandy
Kotlin Kandy: Create Fix Sized Sublists From Iterables With chunked

A blog about Groovy, Clojure, Java and other cool developer subjects.

Messages from mrhaki
New post JDriven blog: Kotlin Kandy: Padding Strings #Kotlin #KotlinKandy https://blog.jdriven.com/2022/12/Kotlin-Kandy-Padding-Strings/
Kotlin Kandy: Padding Strings

Kotlin extends the String class with a couple of padding methods. These methods allows us to define a fixed width a string value must occupy. If the string itself is less than the fixed width then the

JDriven Blog
New post JDriven blog: Kotlin Kandy: Strip Leading Spaces From Multiline Strings #Kotlin #KotlinKandy https://blog.jdriven.com/2022/12/Kotlin-Kandy-Strip-Leading-Spaces-From-Multiline-Strings/
Kotlin Kandy: Strip Leading Spaces From Multiline Strings

Multiline strings are very useful. But sometimes we want use the multiline string without the leading spaces that are added because of code formatting. To remove leading spaces we can use the trimInde

JDriven Blog