What's the difference between next() and nextLine() methods from Scanner class?

后端 未结 14 1998
你的背包
你的背包 2020-11-21 05:32

What is the main difference between next() and nextLine()?
My main goal is to read the all text using a Scanner which may be \"con

14条回答
  •  孤街浪徒
    2020-11-21 06:20

    From JavaDoc:

    • A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace.
    • next(): Finds and returns the next complete token from this scanner.
    • nextLine(): Advances this scanner past the current line and returns the input that was skipped.

    So in case of "small exampletext" next() should return "small" and nextLine() should return "small example"

提交回复
热议问题