What is the efficient way to list the unique List[String]'s from an Array[List[String]]?
up vote
0
down vote
favorite
I want to find unique List[String] from an Array[List[String]].
For example,
suppose we have an Array of the following List[String]
[a, b, c]
[a, b]
[a, b]
[a, c]
The expected result would be
[a, b, c]
[a, b]
[a, c]
scala
add a comment |
up vote
0
down vote
favorite
I want to find unique List[String] from an Array[List[String]].
For example,
suppose we have an Array of the following List[String]
[a, b, c]
[a, b]
[a, b]
[a, c]
The expected result would be
[a, b, c]
[a, b]
[a, c]
scala
3
myALS.distinct
– jwvh
Nov 8 at 22:20
Same method you use to find unique anything fromArray[anything].
– n.m.
Nov 9 at 6:27
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to find unique List[String] from an Array[List[String]].
For example,
suppose we have an Array of the following List[String]
[a, b, c]
[a, b]
[a, b]
[a, c]
The expected result would be
[a, b, c]
[a, b]
[a, c]
scala
I want to find unique List[String] from an Array[List[String]].
For example,
suppose we have an Array of the following List[String]
[a, b, c]
[a, b]
[a, b]
[a, c]
The expected result would be
[a, b, c]
[a, b]
[a, c]
scala
scala
edited Nov 9 at 22:18
thebluephantom
2,1362823
2,1362823
asked Nov 8 at 21:51
Abir Chokraborty
1991116
1991116
3
myALS.distinct
– jwvh
Nov 8 at 22:20
Same method you use to find unique anything fromArray[anything].
– n.m.
Nov 9 at 6:27
add a comment |
3
myALS.distinct
– jwvh
Nov 8 at 22:20
Same method you use to find unique anything fromArray[anything].
– n.m.
Nov 9 at 6:27
3
3
myALS.distinct– jwvh
Nov 8 at 22:20
myALS.distinct– jwvh
Nov 8 at 22:20
Same method you use to find unique anything from
Array[anything].– n.m.
Nov 9 at 6:27
Same method you use to find unique anything from
Array[anything].– n.m.
Nov 9 at 6:27
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Yes. You can apply .distinct in Array(List(String))
def distinct: Array[List[String]]
Builds a new mutable indexed sequence from this mutable indexed
sequence without any duplicate elements.
Returns
A new mutable indexed sequence which contains the first occurrence of
every element of this mutable indexed sequence.
Try the below snippet
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)
OUTPUT
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))
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Yes. You can apply .distinct in Array(List(String))
def distinct: Array[List[String]]
Builds a new mutable indexed sequence from this mutable indexed
sequence without any duplicate elements.
Returns
A new mutable indexed sequence which contains the first occurrence of
every element of this mutable indexed sequence.
Try the below snippet
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)
OUTPUT
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))
add a comment |
up vote
1
down vote
accepted
Yes. You can apply .distinct in Array(List(String))
def distinct: Array[List[String]]
Builds a new mutable indexed sequence from this mutable indexed
sequence without any duplicate elements.
Returns
A new mutable indexed sequence which contains the first occurrence of
every element of this mutable indexed sequence.
Try the below snippet
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)
OUTPUT
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))
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Yes. You can apply .distinct in Array(List(String))
def distinct: Array[List[String]]
Builds a new mutable indexed sequence from this mutable indexed
sequence without any duplicate elements.
Returns
A new mutable indexed sequence which contains the first occurrence of
every element of this mutable indexed sequence.
Try the below snippet
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)
OUTPUT
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))
Yes. You can apply .distinct in Array(List(String))
def distinct: Array[List[String]]
Builds a new mutable indexed sequence from this mutable indexed
sequence without any duplicate elements.
Returns
A new mutable indexed sequence which contains the first occurrence of
every element of this mutable indexed sequence.
Try the below snippet
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)
OUTPUT
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))
answered Nov 9 at 6:28
Unmesha SreeVeni
2,86073867
2,86073867
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53216696%2fwhat-is-the-efficient-way-to-list-the-unique-liststrings-from-an-arraylists%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
myALS.distinct– jwvh
Nov 8 at 22:20
Same method you use to find unique anything from
Array[anything].– n.m.
Nov 9 at 6:27