Advanced use of Scala list

an introduction

Introduce some higher-order functions of List
 
two code
  1. C:\Users\lenovo>scala
  2. Welcome to Scala2.12.1(JavaHotSpot(TM)64-BitServer VM,Java1.8.0_101).
  3. Typein expressions for evaluation.Ortry:help.
  4. scala> val l =List(1,2,3)
  5. l:List[Int]=List(1,2,3)
  6. scala> l.filter(x=>x%2==1)
  7. res0:List[Int]=List(1,3)
  8. scala>"99 Red Balloons".toList
  9. res1:List[Char]=List(9,9,, R, e, d,, B, a, l, l, o, o, n, s)
  10. scala>"99 Red Balloons".toList.filter(x=>Character.isDigit(x))
  11. res2:List[Char]=List(9,9)
  12. scala>"99 Red Balloons".toList.takeWhile(x=>x!='B')
  13. res3:List[Char]=List(9,9,, R, e, d,)
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326988186&siteId=291194637