• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scanner Doubt!  RSS feed

 
palla sridhar
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers!
Please consider the following code.

and the output is:



Why in the output , "red" and "blue" are printed, if they do not match the delimiter pattern??
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because next() doesn't show you the delimiters - it shows you the things between the delimiters. That's the point.
 
palla sridhar
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is OK. But the delimiter pattern says, "fish" followed by 1 or more spaces. But after "red" and "blue" there is a space, fish, space which does not represent the delimiter pattern. Then why do they get printed in the output. That's my question.

Thanks
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not "red" and "blue" that's being printed, but "red " and "blue " (note the extra space). When you print another character after the strings, like |, you'll see the extra space.
 
palla sridhar
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks All!
I got it..

Bye
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!