AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Kotlin immutable list10/10/2023 So I don't actually need to say too much more about them. But generally you can think of a list in Kotlin, you can work with it in pretty much the same way as you would do in Java. We can look through them, and we're going to talk a bit more about special things we can do with the lists when we get to the chapter on functional programming. Now, the way we work with lists in Kotlin, we've already seen a little bit. That will create for us an empty, mutable list, but we can supply integers into that list. The const modifier in Kotlin is used for compile-time constants. In other words, if we had a mutable list of numbers and I didn't want to provide any initial values, we'd say mutable list of, but I'd put in here in angle brackets int, for example, and leave my brackets empty. When we use mutable list of, we don't have to provide initial values, but if we don't, then we must provide the data type in the form of a generic class. Well, let's go for Monday, Tuesday, and Wednesday. Well, rather than using list of, we can say mutable list of and provide the values. Let's create a list called days, and I want this one to be a mutable list. If we want to create a mutable list, well, we can do that, as we've already seen, by creating a new array list, but there's also a more Kotlin-like syntax that we can use.
0 Comments
Read More
Leave a Reply. |