Posts

Showing posts from March, 2016

Scala Notes

Maps Here the example of Map and the immutable map. import java.net.URL import java.util.Scanner val in = new Scanner( new URL( "https://raw.githubusercontent.com/rdwallis/alice/master/src/main/webapp/WEB-INF/book/10.txt" ).openStream()) var count = Map[String, Int]() //var count = scala.collection.mutable.Map[String, Int]() while (in.hasNext()){ val word = in.next() count.+=(word->(count.getOrElse(word, 0 )+ 1 )) //count(word) = count.getOrElse(word,0)+1 } count( "Alice" ) Above code segment, mutable Map is commented. This is an exercise I did from the Scala for the Impatient .