• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Scanner Doubt!

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22855
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks All!
I got it..

Bye
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic