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

后端 未结 14 2025
你的背包
你的背包 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:24

    Both functions are used to move to the next Scanner token.

    The difference lies in how the scanner token is generated

    next() generates scanner tokens using delimiter as White Space

    nextLine() generates scanner tokens using delimiter as '\n' (i.e Enter key presses)

提交回复
热议问题