Auto generation of array(string)

You can start with an Array and build its elements. Array.tabulate(26)(x => (x+’a’).toChar.toString * k) Or you can start with the elements and then transition to an Array. (‘a’ to ‘z’).map(_.toString * k).toArray

Write Java Program to grade Scala Homeworks

Scala generates class files. Scala class files can be run with java, only requiring the scala-library.jar to be on the class path. The entry point on Scala programs appears to Java as a static main method on a class, just like in Java. The difference is that, in a Scala program, that main method is … Read more

Scala Iterable[(String, Long)] to SortedMap[String,Long] or TreeMap[String, Long] sorted in decreasing order of value [closed]

You can’t do that. SortedMap sorts by keys, not values. If you want it sorted by value, you gotta use ListMap, and can’t avoid converting to List: ListMap(i.toList.sortBy(-_._2):_*) There isn’t really too much wrong with converting to list, since you are loading the whole thing in memory anyway. This is faster too, than building a … Read more

Real life example of List,Tuple,Set and Map

You can use a List to store the steps necessary to cook a chicken, because Lists support sequential access and you can access the steps in order. You can use a Tuple to store the latitude and longitude of your home, because a tuple always has a predefined number of elements (in this specific example, … Read more