Java Scanner.remove()

Syntax

Scanner.remove() has the following syntax.

public void remove()

Example

In the following code shows how to use Scanner.remove() method.


//from   w  w  w.  j  ava 2  s.c  om
import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

      String s = "java2s.com 1 + 1 = 2.0 true ";

      Scanner scanner = new Scanner(s);

      System.out.println(scanner.nextLine());

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

      scanner.close();
   }
}

The code above generates the following result.