Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 斯卡拉“;删除“;不起作用_Scala - Fatal编程技术网

Scala 斯卡拉“;删除“;不起作用

Scala 斯卡拉“;删除“;不起作用,scala,Scala,根据《Scala编程》一书的第44页,对于列表数据结构,存在一个remove函数。然而,当我在我的解释器中尝试这个例子时,我不断地得到错误。有人知道为什么吗?这是一个样本 scala> val x = List(1,2,3,4,5,6,7,8,9) x: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9) scala> x.remove(_ < 5) <console>:9: error: value remove is not

根据《Scala编程》一书的第44页,对于
列表
数据结构,存在一个
remove
函数。然而,当我在我的解释器中尝试这个例子时,我不断地得到错误。有人知道为什么吗?这是一个样本

scala> val x = List(1,2,3,4,5,6,7,8,9)
x: List[Int] = List(1, 2, 3, 4, 5, 6, 7, 8, 9)

scala> x.remove(_ < 5)
<console>:9: error: value remove is not a member of List[Int]
              x.remove(_ < 5)
                ^

scala> x.remove(s => s == 5)
<console>:9: error: value remove is not a member of List[Int]
              x.remove(s => s == 5)
                ^

scala> val y = List("apple","Oranges","pine","sol")
y: List[String] = List(apple, Oranges, pine, sol)

scala> y.remove(s => s.length ==4)
<console>:9: error: value remove is not a member of List[String]
              y.remove(s => s.length ==4)
scala>valx=List(1,2,3,4,5,6,7,8,9)
x:List[Int]=List(1,2,3,4,5,6,7,8,9)
scala>x.remove(<5)
:9:错误:值删除不是列表[Int]的成员
x、 移除(u5)
^
scala>x.remove(s=>s==5)
:9:错误:值删除不是列表[Int]的成员
x、 移除(s=>s==5)
^
scala>val y=List(“苹果”、“橙子”、“松树”、“太阳树”)
y:List[String]=List(苹果、橘子、松树、太阳)
scala>y.remove(s=>s.length==4)
:9:错误:值删除不是列表[字符串]的成员
y、 移除(s=>s.length==4)

有删除方法,但没有。请参阅(显然是创建一个新列表!)

List
在早期版本中有一个remove方法,但它在2.8中被弃用,在2.9中被删除。请改用
filterNot

您能更具体一点吗?在弃用过滤器中,过滤器没有被命名为替换,一个测试为我产生了相同的结果。我的错误。我记错了
-