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.
In [14]:
// Create an immutable map with three key value pairs
val staff = Map("CEO" -> "Judith Jackson",
"CFO" -> "Sally Shields",
"CTO" -> "Steven Miller")
In [18]:
// Test if key exists
staff.contains("CTO")
Out[18]:
In [16]:
// Test is any value exists which contains part of a string
staff.valuesIterator.exists(_.contains("Miller"))
Out[16]: