Question | Click to View Answer |
What does the following code print? val simple = Map("r" -> "red", "g" -> "green")
println(simple("g"))
|
A map is a collection of key / value pairs as tuples. In the |
What does the following code print? val airport = Map("jfk" -> "new york", "lga" -> "new york")
println(airport("lax"))
|
This code throws a The |
What does the following code print? val player = Map("skates" -> "bauer", "stick" -> "nike")
println(player.contains("stick"))
|
The |
What does the following code print? val cool = Map("a" -> "aaa", "b" -> "bbb", "a" -> "ccc")
println(cool("a"))
|
The |
What does the following code print? val numbers = Map(1 -> "one", 2 -> "two", 3 -> "three")
val odds = numbers - 2
println(odds)
|
The |
What does the following code print? val some = Map(23 -> "twenty three")
val more = some + (8 -> "eight")
println(more)
|
Notice that the |
What does the following code print? val shoes = collection.mutable.Map("jordan" -> "nike")
shoes += ("griffey" -> "nike")
println(shoes)
|
|
What does the following code print? val animals = Map("fox" -> "sly")
animals += ("cheetah" -> "fast")
println(animals)
|
This code throws an error. The |
What does the following code print? val birthYears = Map("lebron" -> 1984, "jordan" -> 1963)
val yearSum = birthYears.foldLeft(0) { case (memo: Int, (name: String, year: Int)) =>
memo + year
}
println(yearSum / birthYears.size)
|
The code iterates over the |