您的位置:首页 > 其它

next()和nextLine()方法的区别

2015-12-04 17:51 363 查看
next()方法是不接收空格的,在接收到有效数据前,所有的空格或者tab键等输入被忽略,若有有效数据,则遇到这些键退出。
nextLine()可以接收空格或者tab键,其输入应该以enter键结束。

下面是API说明:

public String next()

Finds and returns the next complete token from this scanner. A complete token is preceded and followed by
input that matches the delimiter pattern. This method may block while waiting for input to scan, even if a previous invocation of
hasNext()
returned
true
.
public String nextLine()

Advances this scanner past the current line and returns the input that was skipped. This method returns the
rest of the current line, excluding any line separator at the end. The position is set to the beginning of the next line.

Since this method continues to search through the input looking for a line separator, it may buffer all of the input searching for the line to skip if no line separators are present.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: