How to get intersection of two strings in Scala

1 Answer

0 votes
val string1 = "php"
val string2 = "python"

// Convert strings to sets of characters and find the intersection
val intersection = string1.toSet.intersect(string2.toSet)

// Convert the result back to a string if needed
val result = intersection.mkString

println(result) 
 
 
  
/*
run:
 
ph
 
*/

 



answered Jul 7, 2025 by avibootz
...