w3resource

Scala Map: Exercises, Practice, Solutions

Scala collection Map: Exercises Practice Solution [ 20 exercises with solution ]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

1. Write a Scala program to create an empty map and add key-value pairs to it.
Click me to see the sample solution

2. Write a Scala program to create a map and check if it is empty or not.
Click me to see the sample solution

3. Write a Scala program to create a map and find the size of the map.
Click me to see the sample solution

4. Write a Scala program to create a map and retrieve the value associated with a given key.
Click me to see the sample solution

5. Write a Scala program to create a map and update the value associated with a given key.
Click me to see the sample solution

6. Write a Scala program to create a map and remove a key-value pair from it.
Click me to see the sample solution

7. Write a Scala program to create a map and iterate over its key-value pairs.
Click me to see the sample solution

8. Write a Scala program to create a map and check if it contains a specific key.
Click me to see the sample solution

9. Write a Scala program to create a map and check if it contains a specific value.
Click me to see the sample solution

10. Write a Scala program to create a map and find the minimum value in the map.
Click me to see the sample solution

11. Write a Scala program to create a map and find the maximum value in the map.
Click me to see the sample solution

12. Write a Scala program to create a map and find the sum of all values in the map.
Click me to see the sample solution

13. Write a Scala program to create a map and find the average of all values in the map.
Click me to see the sample solution

14. Write a Scala program to create a map and find the keys with the maximum value.
Click me to see the sample solution

15. Write a Scala program to create a map and find the keys with the minimum value.
Click me to see the sample solution

16. Write a Scala program to create a map and sort it by keys in ascending order.
Click me to see the sample solution

17. Write a Scala program to create a map and sort it by values in ascending order.
Click me to see the sample solution

18. Write a Scala program to create a map and find the common keys between two maps.
Click me to see the sample solution

19. Write a Scala program to create a map and merge it with another map.
Click me to see the sample solution

20. Write a Scala program to create a map and find the difference between two maps.
Click me to see the sample solution

More ...

Scala Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.

Test your Python skills with w3resource's quiz



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/scala-exercises/map/index.php