Scala 列出唯一列表[String]';是否从数组[列表[字符串]]中删除?

Scala 列出唯一列表[String]';是否从数组[列表[字符串]]中删除?,scala,Scala,我想从数组[List[String]中查找唯一的List[String] 比如说,, 假设我们有以下列表[字符串] [a, b, c] [a, b] [a, b] [a, c] 预期结果将是 [a, b, c] [a, b] [a, c] 对。您可以在数组(列表(字符串))中应用.distinct def distinct:Array[列表[字符串]] 从该可变索引生成新的可变索引序列 没有任何重复元素的序列 返回 一个新的可变索引序列,其中包含 这个可变索引序列的每个元素 请尝试下面的代码

我想从
数组[List[String]
中查找唯一的
List[String]

比如说,, 假设我们有以下
列表[字符串]

[a, b, c]
[a, b]
[a, b]
[a, c]
预期结果将是

[a, b, c]
[a, b]
[a, c]

对。您可以在数组(列表(字符串))中应用.distinct

def distinct:Array[列表[字符串]]

从该可变索引生成新的可变索引序列 没有任何重复元素的序列

返回

一个新的可变索引序列,其中包含 这个可变索引序列的每个元素

请尝试下面的代码片段

import org.apache.spark.sql.SparkSession

object StackTest {
  def main(args: Array[String]): Unit = {

    System.setProperty("hadoop.home.dir", "C:\\hadoop")
    val spark = SparkSession
      .builder()
      .config("spark.master", "local[1]")
      .appName("StackOverFlow")
      .getOrCreate()

    spark.sparkContext.setLogLevel("WARN")

    val hc = spark.sqlContext
    import spark.implicits._

    //Define Array[List[String]]
    var myArrList = Array(List("a","b","c"),List("a","b"),List("a","b"),List("a","c"))
    println("ArrayList: "+ myArrList.deep)

    var distinctMyArrList = myArrList.distinct
    println("Distinct ArrayList: "+ distinctMyArrList.deep)

  }
}
输出

ArrayList: Array(List(a, b, c), List(a, b), List(a, b), List(a, c))
Distinct ArrayList: Array(List(a, b, c), List(a, b), List(a, c))

myALS.distinct
与从
数组[任何内容]
中查找唯一内容时使用的方法相同。