collections

Laptop with Kotlin code open
Tutorials

Lazy Computation in Kotlin: The sequence Builder and How It Can Save Your Memory

The Hidden Cost of Eager Collections Kotlin’s collection functions — map, filter, flatMap — are a joy to use. But they share one characteristic that can quietly hurt your app: they’re eager. Each call processes the entire source and allocates a brand new intermediate list. Chain three or four of them on a list of […]

, , , , ,
Tutorials

Stop Using mutableListOf + toList(): Meet Kotlin’s buildList, buildMap, and buildSet

A Familiar But Slightly Awkward Pattern If you’ve written Kotlin for a while, you’ve almost certainly written code like this: fun getActiveUsers(users: List): List { val result = mutableListOf() for (user in users) { if (user.isActive) result.add(user) if (user.isPremium) result.add(user.copy(label = “Premium”)) } return result.toList() // convert back to read-only } The pattern works, but

, , , , ,
Kotlin collections and mutability
Articles, Tutorials

Kotlin Mutable and Immutable Collections

In this article I would like to emphasise over a few options that we have when working with data structure and more precisely with collections in a mutable and immutable fashion. So let’s start with a few of them and see their mutability state. But first, what makes a list mutable or immutable? Immutable Collections

, , , ,
Scroll to Top