What's the difference between single quote and double quotes in line.split()?

cca-175
#1

I am working on the cca-175 practice questions. I am given a text file which is split by ‘|’:
Christopher|Jan 11, 2015, |5
Kapil|11 Jan, 2015|5
Thomas|6/17/2014|5
J0hn|22-08-2013|5
Mithun|2013|5
Jitendra||5

Then I saved the file as an RDD and tried to map it. However, when used single quote and double quote in the split( ) method, scala returns two different outcomes and using the single quote is right.
Using single quote( split(’|’) ), it returned: Array[String] = Array(Christopher, Jan 11, 2015, 5), which is right.
Using double quote ( split("|")), it returned : Array[String] = Array(C, h, r, i, s, t, o, p, h, e, r, |, J, a, n, " ", 1, 1, , " ", 2, 0, 1, 5, |, 5), which is not what I need.



Can anyone help me with the question?
Thanks!

0 Likes

#2

Hi,
split(’|’) - represents a Char where split(’’|’’) represents a String.

Below link will give more information,

0 Likes