Venu A Positive
Venu A Positive

Reputation: 3062

Why array values not displaying within a Quotes in Scala?

Please carefully observe these two scenarios.

scala> var aa ="ABCD, aaaa, fdad and others, lkda;fd, fdaf".split(",")

aa: Array[String] = Array(ABCD, " aaaa", " fdad and others", " lkda;fd", " fdaf")

scala> var aa ="ABCD, aaaa, fdad and others, lkda;fd, fdaf".split(" ")

aa: Array[String] = Array(ABCD,, aaaa,, fdad, and, others,, lkda;fd,, fdaf)

in first scenario split based on comma (,) In this scenario first word not showing within "quotes" rest of the words showing within "quotes". Why?

In second scenario separate by comma here everything displaying without "Quotes" Why ? Usually Strings display within a quotes, but here not displaying like that why?

Upvotes: 1

Views: 69

Answers (1)

ntalbs
ntalbs

Reputation: 29458

This is not relevant to array. It's the problem of how string literal is displayed on scala REPL. Take a look at the following example:

scala> "hello"
res0: String = hello

scala> "  hello  "
res1: String = "  hello  "

The first string "hello" is displayed as just hello, however, the second is displayed as " hello ". Why? The first string is obvious to recognize without the quotes. But the second contains white spaces before and after hello. Without quotes, it's very hard to recognize that there are white spaces. So it print the string within quotes.

Upvotes: 6

Related Questions