0
0

Javaで「スキャナの入力ストリームにまだ値が残っているか確認する」の動作を確認してみた

Posted at

概要

Javaで「スキャナの入力ストリームにまだ値が残っているか確認する」の動作を確認してみました。以下のページを参考にしました。

実装

以下のファイルを作成しました。

JSample6_5.java
import java.util.Scanner;
import java.util.regex.Pattern;

class JSample6_5{
  public static void main(String[] args){
    String regex = "[A-Z0-9]{2}";
    var p = Pattern.compile(regex);

    Scanner scanner = new Scanner("AB 7B DEB A5");

    while (scanner.hasNext(p)){
      System.out.println(scanner.next());
    }
  }
}

以下のコマンドを実行しました。

$ javac JSample6_5.java 
$ java JSample6_5 
AB
7B

まとめ

何かの役に立てばと。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0