Java.util.Scanner.remove() Method


Advertisements


Description

The java.util.Scanner.remove() method is not supported by this implementation of Iterator.

Declaration

Following is the declaration for java.util.Scanner.remove() method

public void remove()

Parameters

NA

Return Value

This method does not return a value.

Exception

UnsupportedOperationException − if this method is invoked.

Example

The following example shows the usage of java.util.Scanner.remove() method.

Live Demo
package com.tutorialspoint;

import java.util.*;

public class ScannerDemo {
   public static void main(String[] args) {

      String s = "Hello World! 3 + 3.0 = 6.0 true ";

      // create a new scanner with the specified String Object
      Scanner scanner = new Scanner(s);

      // print a line of the scanner
      System.out.println("" + scanner.nextLine());

      // attempt to call remove results in an exception
      scanner.remove();

      // close the scanner
      scanner.close();
   }
}

Let us compile and run the above program, this will produce the following result −

Hello World! 3 + 3.0 = 6.0 true 
Exception in thread "main" java.lang.UnsupportedOperationException

java_util_scanner.htm

Advertisements
E-Books Store