From the course: Build Spring Boot Apps with the Kotlin Programming Language

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Maps and sets

Maps and sets

- [Instructor] So let's move on to maps and sets. Well, you can probably guess we have similar methods to this list of and mutable list of to create maps for us and to create sets for us. For example, if we wanted to have a set of months that's immutable, we'd go for set of, and let's just go for Jan and Feb. If we wanted to make it a mutable set, we would put in mutable set of. And you can probably guess that we do maps in the same way. So let's have a map of web colors. We'll make it an immutable map, so it's just map of, and now the syntax here is slightly different. To provide the key value pairs, we do key, then the keyword to, and then the value. So for example, we might want to map red to FF0000, comma, and then our next key value pair, so we'll map blue to 00FF00, and so on. Again, if we were making this a mutable map, then we wouldn't have to provide initial values. We could do it like we do the mutable list. But we do need to provide the data types using this generic. When…

Contents