Let's read the docs for skip
:
Skips input that matches a pattern constructed from the specified string.
So skip
tells the scanner to not read some parts of the user input, and continue after those parts. Here, your pattern matches a Windows new line character \r\n
, or one of these...
- U+2028 LINE SEPARATOR
- U+2029 PARAGRAPH SEPARATOR
- U+0085 NEXT LINE (NEL)
...if such a pattern exists.
Why does the programmer write this? A possible explanation is to avoid the next call to nextLine
returning an empty string. See this question for why this happens.
Would i replace with another method to get the same result?
You could call skip(Pattern.compile("..."))
, but really it's just another overload of the same method. The closest to what you are doing is probably nextLine
, which uses a similar pattern to yours.