Filter and filterNot
📖 Scenario: You are managing a list of products in a store. Some products are on sale, and you want to separate the sale items from the regular items.
🎯 Goal: Build a Kotlin program that uses filter and filterNot to create two lists: one with products on sale and one with products not on sale.
📋 What You'll Learn
Create a list of products with their sale status
Create a variable to hold the sale status to filter by
Use
filter to get products on saleUse
filterNot to get products not on salePrint both filtered lists
💡 Why This Matters
🌍 Real World
Filtering lists is common when you want to separate data based on conditions, like showing only available products or filtering messages.
💼 Career
Understanding how to filter collections is important for data processing, user interface updates, and backend logic in many programming jobs.
Progress0 / 4 steps