This codelab discusses how to work with multiple values in your code, and introduces a variety of data structures, including arrays, lists, sets, and maps. The ability to effectively use collections enables you to implement common features of Android apps, such as scrolling lists, as well as solve a variety of real-life programming problems that involve arbitrary amounts of data. A collection might be an ordered list, a grouping of unique values, or a mapping of values of one data type to values of another. To build apps involving arbitrary amounts of data, you need to learn how to use collections.Ĭollection types (sometimes called data structures) let you store multiple values, typically of the same data type, in an organized way. However, in the code you've written so far, you've mostly worked with data consisting of a single value, like a number or piece of text displayed on the screen. The correct syntax for creating an array with explicit values is to use arrayOf or intArrayOf.In many apps, you've probably seen data displayed as a list: contacts, settings, search results, etc. So you've created a 3x3 matrix that is completely filled with the number 23. Your lambda that you pass to that IntArray constructor is throwing away a bunch of pointless Int values and then returning 23 for each item. You are also instantiating your array incorrectly to begin with. So in this case it is the array index, and your lambda is returning 0 and 1 for even and odd indices respectively. The lambda that you pass to the IntArray constructor has an input parameter that represents the array index, and the return value of your lambda is what will be put into the array at that index. You are creating a brand new group of array objects by calling the Array and IntArray constructors. Isn't doing anything to the original Array that result is pointing at.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |