9/1/2023 0 Comments Mapof in kotlin![]() ![]() So, David will be the key of the first element. But now, let's try to add the elements of the array inside the parentheses. Of course, you can specify any data type that you want here. So now, I've got to determine the data type of the element that I will add to the array. Right, the mapOf between the chevron marks. So, I said the name of the array to be age. So now, that you have the lowdown about map, why don't we open up Android Studio and practice it a little bit? So first, I'll create a Kotlin file, brand new, specify the name, Collections Map. And of course, similarly to print the value 25 to the screen, we will need to use the Ronaldo Key.Ĭool. So, in our example to print the value 20 to the console we will need to use the David key. So, now let's see how to print the elements of an array created with mapOf to the console. The key of the second element is ronaldo and that value would be 25. The key of the first element is david and its value is 20. So, in this example we've got two elements. ![]() All right? So, we now need to write the key and value parameters within parentheses. So, in our example here, the key's type is string. So, the first data type will be the type of key that represents the element we will add to the array and the second data type will be the type of element that we want to add to the array. Between the chevron marks, we need to write two different data types. ![]() So, after specifying the name of the array, we write mapOf to the right of the equal sign. So, let's examine our example on the screen. The feature that distinguishes map from other collections is that we can store elements in the array as key value pairs. That means in this lesson, we're going to learn the map. So, we learned the set in our previous lesson. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |