Java Scanner remove()方法

java.util.Scanner.remove() 不受此实现迭代器的支持的方法。

1 语法

public void remove()

2 参数

3 返回值

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * java.util.Scanner.remove()方法的例子
 */
import java.util.*;

public class Demo {
    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();
    }
}

输出结果为:

Hello World! 3 + 3.0 = 6.0 true 
Exception in thread "main" java.lang.UnsupportedOperationException
	at java.util.Scanner.remove(Scanner.java:1383)
	at com.yiidian.Demo.main(Demo.java:23)

热门文章

优秀文章