mac $ ./scala
cat: /release: No such file or directory
Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112).
Type in expressions for evaluation. Or try :help.
scala> val i =1
i: Int = 1
scala> val s = "hello"
s: String = hello
scala> val str: String = "itcast"
str: String = itcast
scala> val x = 1;
x: Int = 1
scala> val y = if (x > 0) 1 else -1
y: Int = 1
scala> println(y)
1
scala> val z = if (x > 2) 1 else "error"
z: Any = error
scala> val z = if (x > 1) 1 else "error"
z: Any = error
scala> val z = if (x > 0) 1 else "error"
z: Any = 1
scala> val m = if (x >2) 1
m: AnyVal = ()
scala> val n = if (x > 2) 1 else ()
n: AnyVal = ()
scala> val k = if (x < 0) 0
k: AnyVal = ()
scala> val k = if (x < 0) 0 else if (x >=1) 1 else -1
k: Int = 1
scala> val x =0
x: Int = 0
scala> val result = {
| if (x < 0) {
| -1
| }
| else if (x >=1) {
| 1
| } else {
| "error"
| }
| }
result: Any = error
scala> for (i <- 1 to 10)
| println(i)
1
2
3
4
5
6
7
8
9
10
scala> for (i<-1 to 2)
| print(i)
12
scala> val arr = Array("a", "b", "c")
arr: Array[String] = Array(a, b, c)
scala> for (i <- arr)
| print i
<console>:14: error: missing argument list for method print in object Predef
Unapplied methods are only converted to functions when a function type is expected.
You can make this conversion explicit by writing `print _` or `print(_)` instead of `print`.
print i
^
scala> print(i)
1
scala> i
res43: Int = 1
scala> arr
res44: Array[String] = Array(a, b, c)
scala> for (i <-arr)
| println(i)
a
b
c
scala> for(i <- 1 to 3; j <- 1 to 3 if i!=j)
| print ((10 *i +j) + " ")
12 13 21 23 31 32
scala>
scala> val v = for(i <- 1 to 10) yield i * 10
v: scala.collection.immutable.IndexedSeq[Int] = Vector(10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
scala> val v = for(i <- 1 to 10) i *10
v: Unit = ()
scala> val a = 1
a: Int = 1
scala> val b = 3
b: Int = 3
scala> a +b
res47: Int = 4
scala> a.+(b)
res48: Int = 4
scala> def m1(x: Int, y: Int) : Int = x*y
m1: (x: Int, y: Int)Int
scala> m1(3 , 9)
res49: Int = 27
scala> val f1 = (x: Int, y: Int) => x +y
f1: (Int, Int) => Int = $$Lambda$1478/866199557@5b897f0
scala> f1(2, 8)
res50: Int = 10
scala> def m2(f: (Int, Int) => Int) = f(2, 6)
m2: (f: (Int, Int) => Int)Int
scala> val f2 = (x : Int, y: Int) => x -y
f2: (Int, Int) => Int = $$Lambda$1479/1002210819@78e10901
scala> m2(f2)
res51: Int = -4
scala> def m1(f: (Int, Int) => Int) : Int = {}
<console>:11: error: type mismatch;
found : Unit
required: Int
def m1(f: (Int, Int) => Int) : Int = {}
^
scala> def m1(f: (Int, Int) => Int) : Int = { f(2, 6)}
m1: (f: (Int, Int) => Int)Int
scala> val f1 = (x: Int, y : Int) => x +y
f1: (Int, Int) => Int = $$Lambda$1481/876210403@550267a1
scala> val f2 = (m: Int, n: Int) => m * n
f2: (Int, Int) => Int = $$Lambda$1485/2072971801@31461d7c
scala> val r2 = m2(f2)
r2: Int = 12
scala> def m1(x: Int, y: Int) : Int = x* y
m1: (x: Int, y: Int)Int
scala> val f1 = m1 _
f1: (Int, Int) => Int = $$Lambda$1489/474568428@213562e7
scala> val arr1 = new Array[Int](8)
arr1: Array[Int] = Array(0, 0, 0, 0, 0, 0, 0, 0)
scala> println(arr1)
[I@53955236
scala> arr1
res55: Array[Int] = Array(0, 0, 0, 0, 0, 0, 0, 0)
scala> print(arr1)
[I@53955236
scala>
scala> println(arr1.toBuffer)
ArrayBuffer(0, 0, 0, 0, 0, 0, 0, 0)
scala> println(arr1)
[I@53955236
scala> val arr2 = Array[Int](10)
arr2: Array[Int] = Array(10)
scala> println(arr2)
[I@4bd15a8f
scala> println(arr2.toBuffer)
ArrayBuffer(10)
scala> arr2
res67: Array[Int] = Array(10)
scala> arr1
res68: Array[Int] = Array(0, 0, 0, 0, 0, 0, 0, 0)
scala> val arrs3 = Array("hadoop", "storm", "spark")
arrs3: Array[String] = Array(hadoop, storm, spark)
scala> println(arrs3(2))
spark
scala> val ab = ArrayBuffer[Int] ()
<console>:11: error: not found: value ArrayBuffer
val ab = ArrayBuffer[Int] ()
^
scala> import scala
final package scala
scala> import scala
| ._
import scala._
scala> val ab = ArrayBuffer[Int]()
<console>:14: error: not found: value ArrayBuffer
val ab = ArrayBuffer[Int]()
^
scala> import scala.collection.mutable._
import scala.collection.mutable._
scala> val ab = ArrayBuffer[Int]()
ab: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer()
scala> ab
res70: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer()
scala> ab += 1
res71: ab.type = ArrayBuffer(1)
scala> ab += (2, 3, 4, 5)
res72: ab.type = ArrayBuffer(1, 2, 3, 4, 5)
scala> ab ++= Array(3,9)
res73: ab.type = ArrayBuffer(1, 2, 3, 4, 5, 3, 9)
scala> ab ++= ArrayBuffer(6, 12)
res74: ab.type = ArrayBuffer(1, 2, 3, 4, 5, 3, 9, 6, 12)
scala> ab.insert(0, -1 ,0 , 10)
scala> ab
res76: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(-1, 0, 10, 1, 2, 3, 4, 5, 3, 9, 6, 12)
scala> ab.insert(2, 12, 11, 9)
scala> ab
res78: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(-1, 0, 12, 11, 9, 10, 1, 2, 3, 4, 5, 3, 9, 6, 12)
scala>
scala> ab.remove(2, 2)
scala> ab
res80: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(-1, 0, 9, 10, 1, 2, 3, 4, 5, 3, 9, 6, 12)
scala> ab.remove(3, 2)
scala> ab
res82: scala.collection.mutable.ArrayBuffer[Int] = ArrayBuffer(-1, 0, 9, 2, 3, 4, 5, 3, 9, 6, 12)
scala> 0 until 10
res84: scala.collection.immutable.Range = Range 0 until 10
scala> res84
res85: scala.collection.immutable.Range = Range 0 until 10
scala> val arr = Array(1,3, 4, 5,6, 8,9,2)
arr: Array[Int] = Array(1, 3, 4, 5, 6, 8, 9, 2)
scala> for(i <- arr)
| print(i)
13456892
scala> for(i <- (arr.length to 0))
| print(arr[i])
<console>:20: error: not found: type i
print(arr[i])
^
<console>:20: error: value arr of type Array[Int] does not take type parameters.
print(arr[i])
^
scala> 9 to 0
res88: scala.collection.immutable.Range.Inclusive = empty Range 9 to 0
scala> for(i <- 9 to 2)
| println(i)
scala> for(i <- 9 to 13)
| println(i)
9
10
11
12
13
scala> for(i <- (0 until arr.length).reverse)
| println(arr(i))
2
9
8
6
5
4
3
1
scala> val arr = Array(2, 1,3,4,5,9,7)
arr: Array[Int] = Array(2, 1, 3, 4, 5, 9, 7)
scala> val res = for(e <- arr) yield e *2
res: Array[Int] = Array(4, 2, 6, 8, 10, 18, 14)
scala> arr.map(_ * 2)
res92: Array[Int] = Array(4, 2, 6, 8, 10, 18, 14)
scala> val arr = Array(2,3,1,6,7,8)
arr: Array[Int] = Array(2, 3, 1, 6, 7, 8)
scala> val res = for(e <- arr if e % 2 == 0) yield e * 10
res: Array[Int] = Array(20, 60, 80)
scala> println(res.toBuffer)
ArrayBuffer(20, 60, 80)
scala> val r = arr.filter(_ % 2 == 0).map(_ * 10)
r: Array[Int] = Array(20, 60, 80)
scala> val r = arr.filter(_ % 2 ==0)
r: Array[Int] = Array(2, 6, 8)
scala>
scala>
scala> val arr = Array(2,3,5,1,9,5);
arr: Array[Int] = Array(2, 3, 5, 1, 9, 5)
scala> arr.sum
res94: Int = 25
scala> arr.max
res95: Int = 9
scala> arr.sorted
res96: Array[Int] = Array(1, 2, 3, 5, 5, 9)
scala>
scala> val scores = Map("tom" -> 85, "jerry" -> 99, "kitty" -> 90)
scores: scala.collection.mutable.Map[String,Int] = Map(tom -> 85, kitty -> 90, jerry -> 99)
scala> val scores = Map(("tom", 96),("herry", 87), ("tom",91))
scores: scala.collection.mutable.Map[String,Int] = Map(herry -> 87, tom -> 91)
scala> scores("tom")
res97: Int = 91
scala> scores("rose")
java.util.NoSuchElementException: key not found: rose
at scala.collection.MapLike.default(MapLike.scala:232)
at scala.collection.MapLike.default$(MapLike.scala:231)
at scala.collection.AbstractMap.default(Map.scala:59)
at scala.collection.mutable.HashMap.apply(HashMap.scala:65)
... 29 elided
scala> scores.getOrElse("rose", 12)
res99: Int = 12
scala> import scala.collection.mutable.Map
import scala.collection.mutable.Map
scala> val scores = Map("tom" -> 80, "jerry" -> 90)
scores: scala.collection.mutable.Map[String,Int] = Map(tom -> 80, jerry -> 90)
scala> scores("tom")
res100: Int = 80
scala> scores("tom") = 88
scala> scores
res102: scala.collection.mutable.Map[String,Int] = Map(tom -> 88, jerry -> 90)
scala> scores += ("kitty" -> 99)
res103: scores.type = Map(tom -> 88, kitty -> 99, jerry -> 90)
scala> scores += ("kitty" -> 99)
res104: scores.type = Map(tom -> 88, kitty -> 99, jerry -> 90)
scala> scores += ("jerry" -> 99)
res105: scores.type = Map(tom -> 88, kitty -> 99, jerry -> 99)
scala> scores += (("rose", 80))
res106: scores.type = Map(rose -> 80, tom -> 88, kitty -> 99, jerry -> 99)
scala> val t = ("hadoop", 3.14, 678)
t: (String, Double, Int) = (hadoop,3.14,678)
scala> val t(a,b,c) = ("hadoop", 3.13, 4566)
<console>:21: error: value t is not a case class, nor does it have an unapply/unapplySeq member
val t(a,b,c) = ("hadoop", 3.13, 4566)
^
scala> val t,(a,b,c) = ("hadoop", 3.13, 4566)
t: (String, Double, Int) = (hadoop,3.13,4566)
a: String = hadoop
b: Double = 3.13
c: Int = 4566
scala> val r1 =t._1
r1: String = hadoop
scala> val r1 =t.1
<console>:1: error: ';' expected but double literal found.
val r1 =t.1
^
scala> val r2 = t._2
r2: Double = 3.13
scala> val arr = Array(("tom", 98), ("jerry", 90))
arr: Array[(String, Int)] = Array((tom,98), (jerry,90))
scala> arr.toMap
res107: scala.collection.immutable.Map[String,Int] = Map(tom -> 98, jerry -> 90)
scala> val scores = Array(88, 95, 80)
scores: Array[Int] = Array(88, 95, 80)
scala> val ns = names.zip(scores)
<console>:19: error: not found: value names
val ns = names.zip(scores)
^
scala> val names = Array("jim", "tom", "herry")
names: Array[String] = Array(jim, tom, herry)
scala> val ns = names.zip(scores)
ns: Array[(String, Int)] = Array((jim,88), (tom,95), (herry,80))
scala> ns.toMap
res108: scala.collection.immutable.Map[String,Int] = Map(jim -> 88, tom -> 95, herry -> 80)
scala> val l1 = List(2,3,1)
l1: List[Int] = List(2, 3, 1)
scala> val l2 = 0 :: l1
l2: List[Int] = List(0, 2, 3, 1)
scala> val l3 = l1.::(0)
l3: List[Int] = List(0, 2, 3, 1)
scala> val l4 = 0 +: l1
l4: List[Int] = List(0, 2, 3, 1)
scala> val l5 = l1.+:(0)
l5: List[Int] = List(0, 2, 3, 1)
scala> val l6 = l1 :+ 3
l6: List[Int] = List(2, 3, 1, 3)
scala> val l0 = List(5,4,6)
l0: List[Int] = List(5, 4, 6)
scala> val l7 = l1 ++ l0
l7: List[Int] = List(2, 3, 1, 5, 4, 6)
scala> val l8 = l1 ++: l0
l8: List[Int] = List(2, 3, 1, 5, 4, 6)
scala> val l8 = l1 :++ l0
<console>:20: error: value :++ is not a member of List[Int]
val l8 = l1 :++ l0
^
scala> val l9 = l1.:::(l0)
l9: List[Int] = List(5, 4, 6, 2, 3, 1)
scala> val l9 = l1 +++ l0
<console>:20: error: value +++ is not a member of List[Int]
val l9 = l1 +++ l0
^
scala> println(l9)
List(5, 4, 6, 2, 3, 1)
scala> import scala.collection.mutable._
import scala.collection.mutable._
scala> val l0 = ListBuffer[Int](1,3,2)
l0: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 3, 2)
scala> l1
res110: List[Int] = List(2, 3, 1)
scala> val l1 = new ListBuffer[Int]
l1: scala.collection.mutable.ListBuffer[Int] = ListBuffer()
scala> l1 += 4
res111: l1.type = ListBuffer(4)
scala> l1
res112: scala.collection.mutable.ListBuffer[Int] = ListBuffer(4)
scala> l1.append(5)
scala> l1
res114: scala.collection.mutable.ListBuffer[Int] = ListBuffer(4, 5)
scala> l0
res115: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 3, 2)
scala> l0 ++= l1
res116: l0.type = ListBuffer(1, 3, 2, 4, 5)
scala> l0
res117: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 3, 2, 4, 5)
scala> l1
res118: scala.collection.mutable.ListBuffer[Int] = ListBuffer(4, 5)
scala> val l2 = l0 +l1
<console>:23: error: type mismatch;
found : scala.collection.mutable.ListBuffer[Int]
required: String
val l2 = l0 +l1
^
scala> val l2 = l0 + l1
<console>:23: error: type mismatch;
found : scala.collection.mutable.ListBuffer[Int]
required: String
val l2 = l0 + l1
^
scala> val l2 = l0 ++ l1
l2: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 3, 2, 4, 5, 4, 5)
scala> val l3 = l0 :+ 5
l3: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 3, 2, 4, 5, 5)
scala> val l3 = 5 :+ l0
<console>:22: error: value :+ is not a member of Int
val l3 = 5 :+ l0
^
scala> val set1 = new HashSet[Int]()
set1: scala.collection.mutable.HashSet[Int] = Set()
scala> val set2 = set1 +4
set2: scala.collection.mutable.HashSet[Int] = Set(4)
scala> val set3 = set1 ++ Set(6,5,7)
set3: scala.collection.mutable.HashSet[Int] = Set(5, 6, 7)
scala> val set0 = Set(3,1,4) ++ set1
set0: scala.collection.mutable.Set[Int] = Set(1, 3, 4)
scala> println(set0.getClass)
class scala.collection.mutable.HashSet
scala> import scala.collection.mutable
import scala.collection.mutable
scala> val s1 = new mutable.HashSet[Int]()
s1: scala.collection.mutable.HashSet[Int] = Set()
scala> s1 += 2
res120: s1.type = Set(2)
scala> s1.add(4)
res121: Boolean = true
scala> s
res122: String = hello
scala> s1
res123: scala.collection.mutable.HashSet[Int] = Set(2, 4)
scala> a1 ++= Set(3, 1, 5)
<console>:23: error: not found: value a1
a1 ++= Set(3, 1, 5)
^
scala> s1 ++= Set(3, 1, 5)
res125: s1.type = Set(1, 5, 2, 3, 4)
scala> println(s1)
Set(1, 5, 2, 3, 4)
scala> s1
res127: scala.collection.mutable.HashSet[Int] = Set(1, 5, 2, 3, 4)
scala> s1 ++= Set(10, 15, 12)
res128: s1.type = Set(15, 12, 1, 5, 2, 3, 10, 4)
scala> s1 -= 5
res129: s1.type = Set(15, 12, 1, 2, 3, 10, 4)
scala> s1 ++= Set(15)
res130: s1.type = Set(15, 12, 1, 2, 3, 10, 4)
scala> s1.remove(2)
res131: Boolean = true
scala> s1
res132: scala.collection.mutable.HashSet[Int] = Set(15, 12, 1, 3, 10, 4)
scala> println(s1)
Set(15, 12, 1, 3, 10, 4)
scala> import scala.collection.mutable
import scala.collection.mutable
scala>
scala> val m1 = new mutable.HashMap[String, Int]()
m1: scala.collection.mutable.HashMap[String,Int] = Map()
scala> m1("spark") = 1
scala> m1 += (("hadoop", 2))
res135: m1.type = Map(hadoop -> 2, spark -> 1)
scala> m1 += ("hive" -> 3)
res136: m1.type = Map(hadoop -> 2, spark -> 1, hive -> 3)
scala> m1.put("storm",3)
res137: Option[Int] = None
scala> m1
res138: scala.collection.mutable.HashMap[String,Int] = Map(hadoop -> 2, spark -> 1, hive -> 3, storm -> 3)
scala> println(m1)
Map(hadoop -> 2, spark -> 1, hive -> 3, storm -> 3)
scala> m1-="spark"
res140: m1.type = Map(hadoop -> 2, hive -> 3, storm -> 3)
scala> m1.remove("hadoop")
res141: Option[Int] = Some(2)
scala> m1
res142: scala.collection.mutable.HashMap[String,Int] = Map(hive -> 3, storm -> 3)
scala> println(m1)
Map(hive -> 3, storm -> 3)
scala>
scala> val l0 = List(1,2,5,7,8,9,12)
l0: List[Int] = List(1, 2, 5, 7, 8, 9, 12)
scala> val l1 = l0.map(_ * 10)
l1: List[Int] = List(10, 20, 50, 70, 80, 90, 120)
scala> val l2 = l0.filter(_ %2 == 0)
l2: List[Int] = List(2, 8, 12)
scala> l0.sorted
res1: List[Int] = List(1, 2, 5, 7, 8, 9, 12)
scala> l0.add(3,12,5,30)
<console>:13: error: value add is not a member of List[Int]
l0.add(3,12,5,30)
^
scala> l0
res4: List[Int] = List(1, 2, 5, 7, 8, 9, 12)
scala> val l0 = List(6,3,2,1,7,8,9)
l0: List[Int] = List(6, 3, 2, 1, 7, 8, 9)
scala> l0.sorted
res5: List[Int] = List(1, 2, 3, 6, 7, 8, 9)
scala> l0.sorted.reverse
res7: List[Int] = List(9, 8, 7, 6, 3, 2, 1)
scala> l0.grouped(4)
res8: Iterator[List[Int]] = non-empty iterator
scala> l0.grouped(4).toList
res9: List[List[Int]] = List(List(6, 3, 2, 1), List(7, 8, 9))
scala> res8
res10: Iterator[List[Int]] = non-empty iterator
scala> res8.map
<console>:13: error: missing argument list for method map in trait Iterator
Unapplied methods are only converted to functions when a function type is expected.
You can make this conversion explicit by writing `map _` or `map(_)` instead of `map`.
res8.map
^
scala> res8.map(_)
<console>:13: error: missing parameter type for expanded function ((x$1: <error>) => res8.map(x$1))
res8.map(_)
^
scala> res8.map(x => x)
res13: Iterator[List[Int]] = non-empty iterator
scala> res9
res14: List[List[Int]] = List(List(6, 3, 2, 1), List(7, 8, 9))
scala> val lines = List("hello tom hello jerry", "hello jerry", "hell kitty")
lines: List[String] = List(hello tom hello jerry, hello jerry, hell kitty)
scala> val l1 = lines.map(_.split(" "))
l1: List[Array[String]] = List(Array(hello, tom, hello, jerry), Array(hello, jerry), Array(hell, kitty))
scala> val l1 = lines.map(_.split(" ")).toList
l1: List[Array[String]] = List(Array(hello, tom, hello, jerry), Array(hello, jerry), Array(hell, kitty))
scala> val l1 = lines.map(_.split(" "))
l1: List[Array[String]] = List(Array(hello, tom, hello, jerry), Array(hello, jerry), Array(hell, kitty))
scala> val l1 = lines.map(_.split(" ").toList)
l1: List[List[String]] = List(List(hello, tom, hello, jerry), List(hello, jerry), List(hell, kitty))
scala> val l1 = lines.map(_.split(" ").toList).toList
l1: List[List[String]] = List(List(hello, tom, hello, jerry), List(hello, jerry), List(hell, kitty))
scala> val l1 = lines.map(_.split(" ").toList).reduce
<console>:12: error: missing argument list for method reduce in trait TraversableOnce
Unapplied methods are only converted to functions when a function type is expected.
You can make this conversion explicit by writing `reduce _` or `reduce(_)` instead of `reduce`.
val l1 = lines.map(_.split(" ").toList).reduce
^
scala> val l1 = lines.map(_.split(" ").toList).reduce((_, 1))
<console>:12: error: missing parameter type for expanded function ((x$2: <error>) => scala.Tuple2(x$2, 1))
val l1 = lines.map(_.split(" ").toList).reduce((_, 1))
^
scala> lines.flatMap(_.split(" "))
res15: List[String] = List(hello, tom, hello, jerry, hello, jerry, hell, kitty)
scala> lines.flatMap(_.split(" ")).map((_, 1))
res16: List[(String, Int)] = List((hello,1), (tom,1), (hello,1), (jerry,1), (hello,1), (jerry,1), (hell,1), (kitty,1))
scala> lines.flatMap(_.split(" ")).map((_, 1)).groupBy(_._1)
res17: scala.collection.immutable.Map[String,List[(String, Int)]] = Map(kitty -> List((kitty,1)), hell -> List((hell,1)), tom -> List((tom,1)), hello -> List((hello,1), (hello,1), (hello,1)), jerry -> List((jerry,1), (jerry,1)))
scala> lines.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).ma
map mapValues max maxBy
scala> lines.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).ma p
par partition product
scala> lines.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).ma p
par partition product
scala> lines.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).ma p
par partition product
scala> lines.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).ma v
Display all 407 possibilities? (y or n)
scala> lines.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).mapValues
v
override def mapValues[W](f: List[(String, Int)] => W): scala.collection.immutable.Map[String,W]
scala> lines.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).mapValues
override def mapValues[W](f: List[(String, Int)] => W): scala.collection.immutable.Map[String,W]
scala> lines.flatMap(_.split(" ")).map((_,1)).groupBy(_._1).mapValues(_.foldLeft(0)(_+_._2))
res26: scala.collection.immutable.Map[String,Int] = Map(kitty -> 1, hell -> 1, tom -> 1, hello -> 3, jerry -> 2)
scala> lines.flatMap(_.split(" ")).map((_, 1)).groupBy(_._1).map(t => (t._1, t._2.size))
res27: scala.collection.immutable.Map[String,Int] = Map(kitty -> 1, hell -> 1, tom -> 1, hello -> 3, jerry -> 2)
scala> lines.flatMap(_.split(" ")).map((_, 1)).groupBy(_._1).map(t => (t._1, t._2.size)).toList
res28: List[(String, Int)] = List((kitty,1), (hell,1), (tom,1), (hello,3), (jerry,2))
scala> lines.flatMap(_.split(" ")).map((_, 1)).groupBy(_._1).map(t => (t._1, t._2.size)).toList.sortedBy(_._2)
<console>:13: error: value sortedBy is not a member of List[(String, Int)]
lines.flatMap(_.split(" ")).map((_, 1)).groupBy(_._1).map(t => (t._1, t._2.size)).toList.sortedBy(_._2)
^
scala> lines.flatMap(_.split(" ")).map((_, 1)).groupBy(_._1).map(t => (t._1, t._2.size)).toList.sortBy(_._2)
res30: List[(String, Int)] = List((kitty,1), (hell,1), (tom,1), (jerry,2), (hello,3))
scala> lines.flatMap(_.split(" ")).map((_, 1)).groupBy(_._1).map(t => (t._1, t._2.size)).toList.sortBy(_._2).reverse
res31: List[(String, Int)] = List((hello,3), (jerry,2), (tom,1), (hell,1), (kitty,1))