JavaScanner
中的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.
【注1】这里的delimiter pattern默认是正则表达式:\p{javaWhitespace}+
,表示匹配任何空白字符,因此next()
读取的内容默认去掉前后的空白符号;
【注2】可以通过,例如sc.useDelimiter(Pattern.compile(";"));
这样来改变默认的delimiter pattern;这里sc
表示Scanner
的一个对象。
public static void main(String[] args