for(生成器;定义;过滤器) 来做数据过滤查询
package com.dt.scala.forexpression
case class Book(title : String , authors : List[String])
object For_Query {
def main(args: Array[String]) {
val books: List[Book] = List(
Book("Structure and Interpretation ", List("Abelson , Harold", "Sussman")),
Book("Principles of Compiler Design",
List("Aho, Alfred", "Ullman, Jeffrey")),
Book("Programming in Modula-2", List("Wirth, Niklaus")),
Book("Introduction to Functional Programming", List("Bird, Richard")),
Book("The Java Language Specification",
List("Gosling, James", "Joy, Bill", "Steele, Guy", "Bracha, Gilad")))
// val result = for(b <- books ; a <- b.authors if a startsWith "Gosling") yield b.title
val result = for(b <- books if (b.title indexOf "Programming") >= 0 ) yield b.title
println(result)
}
}
DT大数据梦工厂微信公众账号:DT_Spark。
DT大数据梦工厂的微信公众号是DT_Spark,每天都会有大数据实战视频发布,请您持续学习。
王家林DT大数据梦工厂scala的所有视频、PPT和代码在百度云盘的链接:http://pan.baidu.com/share/home?uk=4013289088#category/type=0&qq-pf-to=pcqq.group
QQ群:
DT大数据梦工厂① :462923555
DT大数据梦工厂②: 437123764
DT大数据梦工厂③ :418110145