ListBuffer 将其分配给一个字符串
ListBuffer to assign it to one string
我在 ListBuffer 上创建了循环:
val listOfNamesOfMissingFiles = new ListBuffer[String]()
controlFileContent.entries.foreach { entry =>
val fileName = entry("File_Name")
val sha256 = entry("File_SHA_256")
val file = new File(folder, fileName)
if (!file.exists()) {
logger.error(s"Control file validation failed: file does not exist in folder: [$fileName].")
listOfNamesOfMissingFiles += fileName
}
我想将我在 listOfNamesOfMissingFiles 中获取的内容分配给一个属性,并将其作为事件发送到 kibana 门户。如果我的 listOfNamesOfMissingFiles == ListBuffer("hhhh","uuuu")。如果我做 listOfNamesOfMissingFiles.toString,我会得到“ListBuffer("hhhh","uuuu")”。如何从输出中删除 ListBuffer?
我认为您想要实现的只是加入一个字符串列表。
Scala 提供了 mkString
方法:
scala> val names = ListBuffer("hhhh", "uuuu")
names: scala.collection.mutable.ListBuffer[String] = ListBuffer(hhhh, uuuu)
scala> names.mkString
res0: String = hhhhuuuu
scala> names.mkString(", ")
res1: String = hhhh, uuuu
scala> names.mkString("(", ", ", ")")
res2: String = (hhhh, uuuu)
我在 ListBuffer 上创建了循环:
val listOfNamesOfMissingFiles = new ListBuffer[String]()
controlFileContent.entries.foreach { entry =>
val fileName = entry("File_Name")
val sha256 = entry("File_SHA_256")
val file = new File(folder, fileName)
if (!file.exists()) {
logger.error(s"Control file validation failed: file does not exist in folder: [$fileName].")
listOfNamesOfMissingFiles += fileName
}
我想将我在 listOfNamesOfMissingFiles 中获取的内容分配给一个属性,并将其作为事件发送到 kibana 门户。如果我的 listOfNamesOfMissingFiles == ListBuffer("hhhh","uuuu")。如果我做 listOfNamesOfMissingFiles.toString,我会得到“ListBuffer("hhhh","uuuu")”。如何从输出中删除 ListBuffer?
我认为您想要实现的只是加入一个字符串列表。
Scala 提供了 mkString
方法:
scala> val names = ListBuffer("hhhh", "uuuu")
names: scala.collection.mutable.ListBuffer[String] = ListBuffer(hhhh, uuuu)
scala> names.mkString
res0: String = hhhhuuuu
scala> names.mkString(", ")
res1: String = hhhh, uuuu
scala> names.mkString("(", ", ", ")")
res2: String = (hhhh, uuuu)