Associate for map creation
📖 Scenario: You work in a small bookstore. You have a list of book titles and their prices. You want to create a map where each book title is linked to its price for easy lookup.
🎯 Goal: Build a Kotlin program that creates a map from a list of book titles and a list of prices using the associate function.
📋 What You'll Learn
Create a list of book titles called
books with these exact values: "Kotlin Basics", "Advanced Kotlin", "Kotlin Coroutines"Create a list of prices called
prices with these exact values: 29.99, 39.99, 34.99Create a map called
bookPrices by associating each book title with its corresponding price using associatePrint the
bookPrices map💡 Why This Matters
🌍 Real World
Creating maps from lists is useful when you want to link related data, like product names and prices, for quick access.
💼 Career
Many jobs require handling data collections and transforming them into maps or dictionaries for efficient lookup and processing.
Progress0 / 4 steps