1

Can you please correct my code.I am trying to print x22 by spliting x11.

object ScalaString {

  def main(args: Array[String]): Unit = {
    var x =" Hello world"
    x.filter(_!='l').foreach(println)
    //for(c <- x) println(c)
   println(x.stripPrefix(" ").drop(2).take(2).capitalize)
    **var x11=" hello|world|india"
    var x22=( x11.split("|").map(_.trim()))
    println(x22.toString())**

  }

}

output:
w
o
r
d
Ll
**[Ljava.lang.String;@56431753**

1 Answer 1

5

That's what the toString of an Array looks like. Try x22.mkString instead.

Sign up to request clarification or add additional context in comments.

2 Comments

Hello Boss,Thats worked perfectly. Please let me know what the difference.. Why it was showing the memory address.
The difference is... it's a different function. Array functions in general are optimized for performance rather than anything else; in general e.g. Vector is similar but more user-friendly, and has a toString that returns something more sensible. split returns an Array because that's the java.lang.String API.

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.