Scala编程入门---函数式编程之集合操作

集合的函数式编程:

实战常用:

//map案例实战:为List中的每个元素都添加一个前缀。
List("leo","Jen","peter","jack").map("name is"+ _) #结果: list2("name is leo","name is Jen" ,"name is peter","name is jack") //faltMap案例实战:将List中的多行句子拆分成单词
list("Hello world" ,"Hello me" ,"Hello You") #结果:list("Hello","world","Hello","me","Hello","You") //foreach案例实战:打印list中的每个单词
list("i","have","a","beautiful","house").foreach(println(_))
#结果:i have a beautiful house //zip案例实战:对学生姓名和学生成绩进行关联
list("leo","jen","Peter","Jack").zip(100,90,85,70)
#结果:list((leo,100),(jen,90),(Peter,85),(Jack,70))
上一篇:机器学习笔记(九)---- 集成学习(ensemble learning)【华为云技术分享】


下一篇:MATLAB 下GUI的学习