Java17 Character クラスのallMatch() で全ての要素が条件に一致するか評価する

環境
JavaSE-17
Eclipse 4.24.0 M2

構文
allMatch(Predicate<? super T> predicate)
引数
関数型インタフェースのPredicate

戻り値
boolean
書式
String 変数名 =値
変数名.chars().allMatch(Character::isDigit);

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.study;
public class ArkgameTest {
public static void main(String[] args) {
String str = "4567";
boolean isNumeric = str.chars().allMatch(Character::isDigit);
System.out.println(isNumeric);
str = "xy234";
isNumeric = str.chars().allMatch(Character::isDigit);
System.out.println(isNumeric);
}
}
package com.arkgame.study; public class ArkgameTest { public static void main(String[] args) { String str = "4567"; boolean isNumeric = str.chars().allMatch(Character::isDigit); System.out.println(isNumeric); str = "xy234"; isNumeric = str.chars().allMatch(Character::isDigit); System.out.println(isNumeric); } }
package com.arkgame.study;

public class ArkgameTest {

      public static void main(String[] args) {

            String str = "4567";
            boolean isNumeric = str.chars().allMatch(Character::isDigit);
            System.out.println(isNumeric);
            str = "xy234";
            isNumeric = str.chars().allMatch(Character::isDigit);
            System.out.println(isNumeric);

      }

}

実行結果
true
false

Java

Posted by arkgame