You are viewing a single comment's thread. Return to all comments →
in normal scenario when you dont set the delimiter as \z
scan.next()
will read input till it encounters \n (i.e. new line character)
and once it reads \n it stops! which means \n acts as the
fullstop (or Delimiter).
But in the given problem our input has multiple lines and
we have to read them all in one single string
i.e. we have to also read lines that appear after \n without stopping.
so when we use
scan.useDelimiter("\\Z");
this tells scan to use \Z as Delimiter instead of \n (default) for scan.next()
now meaning of \Z is end of the input or the final terminator
i.e. scan.next() will not stop reading until entire input is read.
Seems like cookies are disabled on this browser, please enable them to open this website
Java String Tokens
You are viewing a single comment's thread. Return to all comments →
in normal scenario when you dont set the delimiter as \z
will read input till it encounters \n (i.e. new line character)
and once it reads \n it stops! which means \n acts as the
fullstop (or Delimiter).
But in the given problem our input has multiple lines and
we have to read them all in one single string
i.e. we have to also read lines that appear after \n without stopping.
so when we use
this tells scan to use \Z as Delimiter instead of \n (default) for scan.next()
now meaning of \Z is end of the input or the final terminator
i.e. scan.next() will not stop reading until entire input is read.