0Pricing
Android Academy · Lesson

Maps and Sets

Key-value and unique collections.

Maps and Sets

A map stores key-value pairs: each unique key points to a value, like a dictionary.

A set stores unique items with no duplicates and no guaranteed order.

Both are collection types beyond lists, useful when you need lookups or uniqueness.

Creating a Map

Use mapOf() with key to value pairs to build a read-only map.

Keys must be unique. Here we map fruit names to prices.

fun main() {
    val prices = mapOf("apple" to 3, "banana" to 2)
    println(prices)
    println("Size: ${prices.size}")
}

All lessons in this course

  1. Lists and Mutable Lists
  2. Maps and Sets
  3. map, filter, forEach
  4. Lambdas and Higher-Order Functions
← Back to Android Academy