Reputation: 593
I have a list of list of strings and I want to concatenate all the unique strings into a single (delimited space) string, something that flatMap
allows one to do. However I am confused about the correct usage of the reduce function when concatenating 2 strings.
Input:
val listStrings: List[List[String]] = List(List("this", "is", "the"), List("this", "here"))
Expected Output (the order does not matter):
String("this is the here")
Upvotes: 0
Views: 1158
Reputation: 40894
If you have colossal amounts of repeating strings to deduplicate, you likely need two steps:
If you only have 2-3 entries, as shown in your example, @jwh's answer in comments suffices.
Upvotes: 1