编程那点事编程那点事

专注编程入门及提高
探究程序员职业规划之道!

集合元素操作

集合元素操作

操作功能作用于
col :+ ele将元素添加到集合尾部Seq
ele +: col将元素添加到集合头部Seq
col + ele在集合尾部添加元素Set、Map
col + (ele1, ele2)将其他集合添加到集合的尾部Set、Map
col - ele将元素从集合中删除Set、Map、ArrayBuffer
col - (ele1, ele2)将子集合从集合中删除Set、Map、ArrayBuffer
col1 ++ col2将其他集合添加到集合尾部Iterable
col2 ++: col1将其他集合添加到集合头部Iterable
ele :: list将元素添加到list的头部List
list2 ::: list1将其他list添加到list的头部List
list1 ::: list2将其他list添加到list的尾部List
set1 `` set2取两个set的并集
set1 & set2取两个set的交集Set
set1 &~ set2取两个set的diffSet
col += ele给集合添加一个元素可变集合
col += (ele1, ele2)给集合添加一个集合可变集合
col ++= col2给集合添加一个集合可变集合
col -= ele从集合中删除一个元素可变集合
col -= (ele1, ele2)从集合中删除一个子集合可变集合
col —= col2从集合中删除一个子集合可变集合
ele +=: col向集合头部添加一个元素ArrayBuffer
col2 ++=: col向集合头部添加一个集合ArrayBuffer

集合的常用方法

集合的常用方法
head、last、tail
length、isEmpty
sum、max、min
count、exists、filter、filterNot
takeWhile、dropWhile
take、drop、splitAt
takeRight、dropRight
sclie
contains、startsWith、endsWith
indexOf
intersect、diff


未经允许不得转载: 技术文章 » 大数据 » 集合元素操作