Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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中的java.util.Scanner_Scala - Fatal编程技术网

如何使用scala中的java.util.Scanner

如何使用scala中的java.util.Scanner,scala,Scala,我尝试使用scala中的java.util.Scanner: val scanner = new java.util.Scanner(System.in) val line = scanner.readLine() println(line) 通过在scala REPL上粘贴或运行scala file.scala,我可以得到以下结果: :2: error: value readLine is not a member of java.util.Scanner val line = scanne

我尝试使用scala中的java.util.Scanner:

val scanner = new java.util.Scanner(System.in)
val line = scanner.readLine()
println(line)
通过在scala REPL上粘贴或运行scala file.scala,我可以得到以下结果:

:2: error: value readLine is not a member of java.util.Scanner
val line = scanner.readLine()
我缺少什么?

java.util.Scanner没有读线,请尝试下一行

java.util.Scanner没有读线try nextLine


最简单的方法似乎是使用JavaConverter将扫描仪用作迭代器:


最简单的方法似乎是使用JavaConverter将扫描仪用作迭代器:


杜斯卡拉,这就是我的意思!在REPL中的扫描仪上完成hehetab是有帮助的;杜斯卡拉,这就是我的意思!在REPL中的扫描仪上完成hehetab是有帮助的;
scala> val scanner = new java.util.Scanner(System.in)
scanner: java.util.Scanner = java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\Q�\E][infinity string=\Q∞\E]

scala> val line = scanner.nextLine()
line: String = foo
import scala.collection.JavaConverters._
...
val input = new Scanner(System.in).asScala
input.head // first element
val asList = input.toList // scala list