1

I have a scenario where Array[String] has got empty space. When i apply replace it doesn't return proper result. What would be mistake in my implementation.

scala> val chk2 =Array("8.0","60.0","")
chk2: Array[String] = Array(8.0, 60.0, "")

scala> val chk3 = chk2.map(x => (x.replace("", "0")))
chk3: Array[String] = Array(080.000, 06000.000, 0)
1
  • I've removed the apache-spark tag since it is unrelated Commented Jun 9, 2017 at 18:27

1 Answer 1

2

You can use map with pattern matching:

chk2.map{ case "" => "0"; case x => x }
// res2: Array[String] = Array(8.0, 60.0, 0)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks..it helped me to fix it.

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.