Title: Search A Map
Slug: search_a_map
Summary: Search A Map Using Scala.
Date: 2017-04-03 12:00
Category: Scala
Tags: Basics
Authors: Chris Albon

If you want to learn more, check out Scala Cookbook and Programming in Scala.

Create A Map


In [14]:
// Create an immutable map with three key value pairs
val staff = Map("CEO" -> "Judith Jackson", 
                "CFO" -> "Sally Shields",
                "CTO" -> "Steven Miller")

Test If Key Exists


In [18]:
// Test if key exists
staff.contains("CTO")


Out[18]:
true

Test If Value Exists


In [16]:
// Test is any value exists which contains part of a string
staff.valuesIterator.exists(_.contains("Miller"))


Out[16]:
true