Java Scanner remove() Method

The remove() method of Java Scanner class is used when remove operation is not supported by this implementation of Iterator.

Syntax

Following is the declaration of remove() method:

Parameter

This method does not accept any parameter.

Returns

The remove() method does not return any value.

Exceptions

UnsupportedOperationException- It will thrown exception if this method is invoked.

Compatibility Version

Java 1.5 and above

Example 1

Output:

Hi All! This is JavaTpoint.
Exception in thread "main" java.lang.UnsupportedOperationException
	at java.base/java.util.Scanner.remove(Scanner.java:1490)
	at myPackage.ScannerRemoveExample1.main(ScannerRemoveExample1.java:10)

Example 2

Output:

Enter Your Name: Java
Name: Java
Exception Found. 
Exception in thread "main" java.lang.UnsupportedOperationException
	at java.base/java.util.Scanner.remove(Scanner.java:1490)
	at myPackage.ScannerRemoveExample2.main(ScannerRemoveExample2.java:12)