Using the Safe Call Operator (?.) in Kotlin
📖 Scenario: Imagine you have a list of people, and each person may or may not have a phone number. You want to safely print the length of each phone number without causing errors if the phone number is missing.
🎯 Goal: Build a Kotlin program that uses the safe call operator ?. to safely access the length of phone numbers in a list of people.
📋 What You'll Learn
Create a list of people with nullable phone numbers
Create a variable to hold the count of people
Use the safe call operator
?. to get the length of each phone number safelyPrint the length of each phone number or
null if missing💡 Why This Matters
🌍 Real World
Handling data where some information might be missing is common in apps, like user profiles with optional phone numbers.
💼 Career
Knowing how to safely access nullable data prevents crashes and bugs in real-world Kotlin applications.
Progress0 / 4 steps