From the course: Scala Essential Training for Data Science

Unlock this course with a free trial

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

Operations on maps

Operations on maps

- [Instructor] Maps are Scala collections that we use to group key value pairs. Let's start with an example. We'll build a collection of country names and country capital cities, and we'll do that by specifying val, so we'll create a value, and we'll call it capitals, and capitals will be a map, and that map will include, let's start with Argentina, and that's the key. And the value is specified by using the dash greater than sign. And we'll set the value to be Buenos Aires. And that is our first key value pair. And let's also specify Canada. And the capital of Canada, of course, is Ottawa. And let's also add Egypt. This capital is Cairo, followed by Liberia, and the capital of Liberia is Monrovia. And we'll go to Netherlands whose capital is Amsterdam. And finally, let's go with the United States. The capital of the United States is Washington, DC. And we'll close that up. And we see here that the Scala repo returns capitals with a map, which is a map from string to string, which is…

Contents