grouped: 将collection按照指定的size组合成多个Vector,返回这个List的iterator。 // groupedprintln("--- grouped ---")vallistgroup = (1to10)vallistgroupIterator = listgroup.grouped(3) println("grouped: "+ listgroup +" with size 3 to: "+ listgroupIterator) listgroupIterator foreach println 输出...
mutable.Buffer 和List 是最快的移除元素操作的集合。这很合理,因为从mutable.Buffer移除元素只是改变它的size。从List的头部移除元素只是得到它的.tail,不需要做数据结构的改变。construct 0 1 4 16 64 256 1,024 4,096 16,192 65,536 262,144 1,048,576 Vector:+ 2 15 99 410 1,730 7,000 28,600...
---map---Map:Range(1,2,3,4,5)to:Vector(1,4,9,16,25)Vector(1,4,9,16,25) filter:生成一个条件过滤后的Range 代码语言:javascript 复制 // filterprintln("--- filter ---")val listFilter=(1to10)println("filter: "+listFilter+" to: "+listFilter.filter(x=>x%2==0))println(list...
One easy way of creating a Map is by passing in a list of pairs, where the first element of each pair defines a key and the second defines a corresponding value. 1 2 scala> val engToDeu = Map(("dog","Hund"), ("cat","Katze"), ("rhinoceros","Nashorn")) engToDeu: scala....
Scala拥有庞大而完整的集合类库,比如Set, List, Vector, Tuple, Map,而有效的泛型能让你肆意组合这些...
res0: scala.collection.immutable.IndexedSeq[Int] = Vector( 1 , 2 , 3 ) 1. 2. 3. 4. 默认实现 在trait上使用apply方法会得到该trait的一个默认实现,例如,Iterable(1,2)返回一个List作为它的默认实现。 scala> Iterable( 1 , 2 ) res0: Iterable[Int] = List( 1 , 2 ) ...
scala> for { | i <- 1 to 9 | j <- i to 9 | } yield i * j res0: scala.collection.immutable.IndexedSeq[Int] = Vector(1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 6, 8, 10, 12, 14, 16, 18, 9, 12, 15, 18, 21, 24, 27, 16, 20, 24, 28, 32, 36, 25, 30, 35...
empty[Int] :+ 1 :+ 2 :+ 3 :+ 4 :+ 5 val revList3: Vector[Int] = Vector(1, 2, 3, 4, 5) // how to get a VectorPattern Matching on Repeated Parameters Speaking of repeated parameter lists, you can also use them in pattern matching: // src/script/scala/progscala3/pattern...
...注: Scala中的Vector类似于Java中的ArrayList,而Scala中的List类似于Java中的LinkedList Scala中的List有两个特殊的子类:::表示非空的List,Nil...表示空的List 函数filter和takeWhile都可以起到过滤的作用,filter会过滤出给定集合中所有满足条件的元素,而takeWhile只会返回第一个满足条件的元素。
Scala - Create Mutable Set Scala - Convert Set to SortedSet Scala - Set &() Method Scala - Set drop() Method Scala - HashSet Scala - Convert Java Set of Shorts to String Scala - Convert Java Set of Floats to Vector Scala - Convert Java Set to StringScala...