prepend(1, 2, 3) //在头部添加元素 list.append(4,5) //在尾部添加元素 list.insert(5,6) //在位置5处添加元素 0 +=: list += 7 += 8 //在前面添加0,后面添加7、8 //合并两个list val list09 = list ++ list9 //将list和list9相连接 list09 ++= list99 //将list99追加到list09 //...
添加完后无需赋给新的数组对象// += 向后追加 +=: 向前追加arr+=1927+=:arr// 推荐使用append() 方法// 向后追加arr.append(36)// 向前添加arr.prepend(11,90,56
contains(elem: Any): Boolean:重载SeqLike的方法,判断List是否包含某元素 exists(p: A => Boolean): Boolean:重载IterableLike的方法,判断List中是否包含满足给定条件的元素 forall(p: A => Boolean): Boolean:重载IterableLike的方法,判断是否List中所有的元素都满足给定条件 filter(p: A => Boolean): List[...
// example: change a string list into a word list val strings: List[String] = List("hello world", "hello scala", "yes no") val splitList: List[Array[String]] = strings.map(_.split(" ")) // divide string to words val flattenList = splitList.flatten println(flattenList) // merg...
List SelfDefinedClass BigInt BigDecimal Null是所有引用类型的子类,Nothing是所有类的子类 -Array在默认类下 - Scala的数组的扩展性和可用性强,只需要在Array基础上添加Set和Map则可基本满足需求 Tuple 元组 定义 可以存放不同类型的元素 一旦创建,就不能修改其中的元素 ...
val buffer = ListBuffer(1, 2, 3) buffer.append(4) // 在尾部添加 buffer.prepend(0) // 在头部添加 // buffer 现在是 ListBuffer(0, 1, 2, 3, 4) 将ListBuffer转换为固定列表: 当你完成所有添加操作后,可以将ListBuffer转换为不可变的List: scala val fixedList = buffer.toList // fixedList...
\ genericBuilder prefixLength to << groupBy prepend toArray WithFilter grouped prependAll toBuffer addString hasDefiniteSize prependToList toIndexedSeq aggregate hashCode product toIterable andThen head reduce toIterator append headOption reduceLeft toList appendAll indexOf reduceLeftOption toMap apply ...
// 1、基本类型转为String类型val str = 1 + ""// 2、string类型转为数值类型val d1 = "3.14".toDoubleval d2 = "1".toInt// 3、小数类型,需先转为Double再转为Int类型val i1 = "3.14".toDouble.toInt// 标记为f的float数能够识别val i02 = "12.5f".toFloat ...
2.9.1 List 2.9.2 Map 2.9.3 ArrayBuffer 2.9.4 Vector 2.9.5 Set 2.9.6 Tuples 2.9.7 常用的集合函数 2.10 Class(类) 2.10.1 构造函数 2.10.2 this 2.10.3 枚举类(trait) 2.10.4 伴生对象(object) 2.10.5 样例类(case) 2.10.6 样例对象 2.11 Traits 2.11.1 trait 2.11.2 抽象类 2.12 函数式...
list2.prepend(100) println(list2) // ListBuffer(100, 1, 2, 3, 4, 5, 6) // 指定位置加元素 list2.insert(1, 101) println(list2) // ListBuffer(100, 101, 1, 2, 3, 4, 5, 6) Delete elements, similar to an array here