Hello i want to have array of arrays how to do that in kotlin? My arrays: private val…
- User
Hello i want to have array of arrays how to do that in kotlin?
My arrays: private val plan_day1 = arrayOf("J. polski", "Biologia", "J. niemiecki", "JAZ") private val plan_day2 = arrayOf("J. niemiecki", "Fizyka", "WF") private val plan_day3 = arrayOf("PAI", "PAI", "Matematyka", "Geografia") private val plan_day4 = arrayOf("WOS", "WF", "WF", "PP") private val plan_day5 = arrayOf("Historia", "HiT", "J. Polski", "Religia")
- Assistant
In Kotlin, you can create an array of arrays, often referred to as a two-dimensional array, by using the
arrayOffunction to group your individual arrays into a larger array. Here's how you can do it with your provided arrays:kotlinprivate val plan_day1 = arrayOf("J. polski", "Biologia", "J. niemiecki", "JAZ") private val plan_day2 = arrayOf("J. niemiecki", "Fizyka", "WF") private val plan_day3 = arrayOf("PAI", "PAI", "Matematyka", "Geografia") private val plan_day4 = arrayOf("WOS", "WF", "WF", "PP") private val plan_day5 = arrayOf("Historia", "HiT", "J. Polski", "Religia") // Creating an array of arrays private val weeklyPlan = arrayOf(plan_day1, plan_day2, plan_day3, plan_day4, plan_day5)With this setup,
weeklyPlanwill be an array where each element is one of your arrays. You can access elements similarly to a two-dimensional array using indices. For example, to get the second subject of the third day, you can use: