0

I have a requirement where i have 2 string like below


val data1 = ("42881644070,13.04148,80.096043,32,2019-05-01 12:32:00,[32435381]#42881685433,13.057927,80.127096,45,2019-05-01 12:32:00,[32435383]#42881685434,13.057927,80.127096,35,2019-05-01 12:32:00,[32435384]")

val data2 = ("42881644070#43848058544#43847944680#43849252675#43849251662#43849943435#43850472762")

I wanted to compare data 2 values to data1 1st item which is id and seperator between item is # here.Also the output should be only the items which is not matching with data2.

Here the output should be Array[String]

Array(42881685433,13.057927,80.127096,45,2019-05-01 12:32:00,[32435383], 42881685434,13.057927,80.127096,35,2019-05-01 12:32:00,[32435384])
2
  • 7
    Please provide some code that you tried ? Commented Jun 17, 2019 at 14:16
  • I tried data1.split("#").flatMap(_.split(",").filter {_.intersect(data2_splt).isEmpty}) But it is wrong its not filtering Commented Jun 17, 2019 at 14:28

1 Answer 1

1

Here is what you can do:

val data1 = "42881644070,13.04148,80.096043,32,2019-05-01 12:32:00,[32435381]#42881685433,13.057927,80.127096,45,2019-05-01 12:32:00,[32435383]#42881685434,13.057927,80.127096,35,2019-05-01 12:32:00,[32435384]"

val data2 = "42881644070#43848058544#43847944680#43849252675#43849251662#43849943435#43850472762"

val array1 = data1.split("#")
val array2 = data2.split("#")

val res = array1.filterNot(elem => array2.contains(elem.split(",").head))
println(res.mkString(","))
// Displays
// 42881685433,13.057927,80.127096,45,2019-05-01 12:32:00,[32435383],42881685434,13.057927,80.127096,35,2019-05-01 12:32:00,[32435384]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.