Using Scanner in Java how can I hasNext(aString) where the string is not regex pattern?

Posted by Parris on Stack Overflow See other posts from Stack Overflow or by Parris
Published on 2009-10-01T20:24:36Z Indexed on 2010/04/14 1:12 UTC
Read the original article Hit count: 296

Filed under:
|
|
|
|

Hi, I am trying to do as my question states, sooo I have the following code which would find the match.

String test = scan.next();
if (test.equals("$let"))
return 1;

However, I would prefer to use hasNext as to not consume a token; however, when i do the following it fails.
if (scan.hasNext("$let"))
return 1;

I realize the when giving has next a variable it expects a pattern, but I thought if i don't have any regex symbols it should work. I also thought $ was possibly some regex symbol so I tried /$ however, that did not work!

Thanks for the help!

© Stack Overflow or respective owner

Related posts about java

Related posts about scanner