-
Set up a map of prices for a number of gizmos that you covet. Then produce a second map with the same keys and the prices at a 10 percent discount.
-
Write a program that reads words from a file. Use a mutable map to count how often each word appears. To read the words, simplyy use a
java.utils.Scanner
:
val in = new java.util.Scanner(new java.io.File("myFile.txt"))
while (in.hasNext()) *process* in.next()
Or look at Chapter 9 for a Scalesque way.
At the end, print out all the words and their counts.
-
Repeat the preceding exercise with an immutable map.
-
Repeat the preceding exercise with a sorted map, so that the words are printed in sorted order.
-
Repeat the preceding exercise with a
java.util.TreeMap
that you adapt to the Scala API. -
Define a linked hash map that maps "Monday" to
java.util.Calendary.MONDAY
, and similarly for the other weekdays. Demonstrate that the elements are visited in insertion order. -
Print a table of all the Java properties reported by the
getProperties
method of thejava.lang.System.class
, like this:
property | value prop | value2
-
Write a function minmax(values: Array[Int]) thjat returns a pair containing the smalles and the largest values in an array.
-
Write a function lteqgt(values: Array[Int], v: Int) that returns a triple containing the counts of values less than V, equal to v and greater than v.
-
What happens when you zip together two strings, such as "Hello".zip("World") ? Come with a plausable use case.