score:75
Accepted answer
You can use
val unwanted = list2.toSet
list1.filterNot(unwanted)
to remove all items in list2
(you don't need knowledge of duplicates in list2
).
score:9
You could try this:
val list1 = List("word1","word2","word2","word3","word1")
val list2 = List("word1","word4")
println(list1.filterNot(list2.contains(_)))
score:15
val list1 = List("word1","word2","word2","word3","word1")
val list2 = List("word1","word4")
list1 diff list2
This will do it.
Source: stackoverflow.com
Related Query
- How to get the difference between two lists?
- How to get the difference between two timestamps in scala
- How to obtain the symmetric difference between two DataFrames?
- How would I get the sum of squares of two Lists in Scala?
- Get the difference between two dates in hours
- how to get months,years difference between two dates in sparksql
- How to get the differences between two ObjectNode jsons in Scala?
- How to get the difference between minimum and maximum stock for each product?
- Scala: How to create a new list from the weighted difference of two lists added to a third
- What's the difference between multiple parameters lists and multiple parameters per list in Scala?
- How does Scala know the difference between "def foo" and "def foo()"?
- How to find the difference/mismatch between two JSON file?
- How to get the product of two RDDs?
- Get difference between two version of delta lake table
- What's the difference between these two ways to declare functions?
- Using zip to find the difference between two strings in Scala
- How do I explain the difference between fold and foldK?
- What's the fundamental difference between those two constructs?
- The difference between Lists and Sets
- Scala | what is the difference between '<-', '->' and '=>' operators and how do they work implicitly?
- What's the difference between these two calls to a function taking a collection of structural types?
- How to find the time difference between 2 date-times in Scala?
- How to get the sum of two elements in a list of Arrays in Scala
- What is the difference between this two following cases of pattern matching in scala
- How to get differences between two JSONs?
- What is the difference between this two Scala definitions
- Shapeless: what the difference between these two approaches of instance derivation?
- What is the difference between these two expressions in a Scala anonymous function?
- What is the difference between multiple argument lists and returning a function?
- How to groupby columns from two dataframes and then apply aggregate difference function between rows?
More Query from same tag
- How to avoid saving state in Scala class?
- Custom decoder for AWS API Gateway using circe
- Scala: Hash ignores initial size (fast hash table for billions of entries)
- Not able to map records in csv into objects of a class in Scala / Spark
- Writting generic function for withcolumn in spark scala
- Spark Streaming df.writeStream generate no output
- Does shapeless play well with type members?
- How to parametrize class and implement method depends on type in Scala
- Scala Generic: The return data type of a method with lower bound type
- How do you disable trusted.packages check for Spring-Kafka JsonDeserializer?
- Scala 3 compiler plugin generating expected code but failing at runtime
- Performance issue in play application
- Scala conflict of types when extending a class
- Understanding Type Members
- How to implement generic function in Scala with two argument types?
- Scala Cross Cutting Concerns with mixin composition stacks
- Scala type signature failing with subclasses
- Refined and existential types for runtime values
- Can Akka actor drop messages from it's mailbox if needed?
- Figuring out chain of implicit invocations
- Upgrading an app running on Lift Framework?
- Feeding Python utf-8 strings to Scala
- SWT Text widget does not show up
- Spark: create a csv file(must use scala and dataframe)
- Spark Kryo deserialization of EMR-produced files fails locally
- Usage of Broadcast Variables when using only Spark-SQL API
- Iterating over an array in JSON with Play 2.1.1
- How i can install Actor Platform with Docker
- In Scala, process a list of items with a Try operation, and keep the original item to report the possible failure
- How to filter a map<String, Int> in a data frame : Spark / Scala