Java Scanner skip() MethodThe skip() is a method of Java Scanner class which skips input that matches the specified pattern, ignoring delimiters. There are two different types of Java Scanner skip() method which can be differentiated depending on its parameter. These are:
1. Java Scanner skip(String pattern) MethodIt is a Scanner class method which skips input that matches the specified pattern, ignoring delimiters. 2. Java Scanner skip(Pattern pattern) MethodIt is a Scanner class method which skips input that matches a pattern constructed from the specified string. SyntaxFollowing are the declarations of skip() method: Parameter
ReturnsThe skip() method returns this Scanner object. ExceptionsNoSuchElementException- It will thrown this Exception if the specified pattern not found. IllegalStateException- It will thrown this Exception if the innvocation is done after Scanner is closed. Compatibility VersionJava 1.5 and above Example 1Output: Left String: World! SSSIT 102 Hindi100 150 123 Example 2Output: 102 131 150 123 Example 3Output: SSSIT 102 Hindi100 150 123 Example 4Output: Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanner.skip(Scanner.java:1843) at java.base/java.util.Scanner.skip(Scanner.java:1860) at myPackage.ScannerSkipExample4.main(ScannerSkipExample4.java:11) Next TopicJava-scanner-tostring-method |