Back to Blog

Kotlin with Copilot: Create a list of 3 letters for weekdays and weekends

Sandy LaneSandy Lane

Video: Kotlin with Copilot: Create a list of 3 letters for weekdays and weekends by Taught by Celeste AI - AI Coding Coach

Watch full page →

Kotlin with Copilot: Create a List of 3-Letter Abbreviations for Weekdays and Weekends

In Kotlin, you can easily create lists to represent collections of data such as days of the week. This example demonstrates how to create two separate lists: one for weekdays and another for weekend days, each containing 3-letter abbreviations for the day names.

Code

// Create a list of 3-letter abbreviations for weekdays
val weekdays = listOf("Mon", "Tue", "Wed", "Thu", "Fri")

// Create a list of 3-letter abbreviations for weekend days
val weekends = listOf("Sat", "Sun")

// Print the lists to verify their contents
println("Weekdays: $weekdays")
println("Weekends: $weekends")

Key Points

  • Kotlin's listOf function creates immutable lists with specified elements.
  • Using 3-letter abbreviations is a concise way to represent days of the week.
  • Separate lists can be used to group related data, such as weekdays and weekends.
  • Lists in Kotlin are type-safe and can be printed directly for easy debugging.