package com.bjsxt.scala
object Scala_List {
def main(args:Array[String]):Unit={
val list=List[String]("hello bjsxt","hello bjsxt","hello shsxt","hello gzsxt")
val result = list.count(s=>{
s.equals("hello sdhsxt")
})
println(result)
val result1=list.filter(s=>{
s.equals("hello bjsxt")
})
result1.foreach(println)
println("以下是循环遍历")
val result3=list.map(s=>{
s.split(" ")
})
result3.foreach(arr=>{
arr.foreach(println)
println("*********************")
})
println("????????????????????????????/")
val result4=list.flatMap(s=>{
s.split(" ")
})
result4.foreach(println)
println("................................")
val list1=List[Int](1,2,3,4,4)
list1.foreach(println)
println(";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;")
for(elem<-list1){
println(elem)
}
}
}
Scala部分:Scala中的list集合学习(包含加强for循环遍历,普通for循环遍历,split切割,count计算,filter过滤)
最新推荐文章于 2023-10-09 08:00:00 发布