Found 7442 Articles for Java

Posix character classes p{Graph} Java regex

Maruthi Krishna
Updated on 09-Jan-2020 10:12:14

582 Views

This class matches all visible characters i.e. alphabets, digits, punctuation marks.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class VisiblieCharacters {    public static void main(String args[]) {       //Reading String from user       System.out.println("Enter a string");       Scanner sc = new Scanner(System.in);       String input = sc.nextLine();       //Regular expression       String regex = "[\p{Graph}]";       //Compiling the regular expression       Pattern pattern = Pattern.compile(regex);       //Retrieving the matcher object       Matcher matcher = pattern.matcher(input);       ... Read More

Posix character classes p{Punct} Java regex

Maruthi Krishna
Updated on 09-Jan-2020 09:59:48

3K+ Views

This class matches punctuation marks. i.e.!"#$%&'()*+, -./:;?@[\]^_`{|}~Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class AlphanumericExample {    public static void main(String args[]) {       //Reading String from user       System.out.println("Enter a string");       Scanner sc = new Scanner(System.in);       String input = sc.nextLine();       //Regular expression       String regex = "[\p{Punct}]";       //Compiling the regular expression       Pattern pattern = Pattern.compile(regex);       //Retrieving the matcher object       Matcher matcher = pattern.matcher(input);       int count = 0; ... Read More

How to implement ToDoubleFunction using lambda expression in Java?

raja
Updated on 13-Jul-2020 12:10:26

781 Views

ToDoubleFunction is a functional interface defined in java.util.function package. This functional interface expects a parameter as input and produces a double-valued result. It is used as an assignment target for a lambda expression or method reference. ToDoubleFunction interface contains only one abstract method, applyAsDouble().Syntax@FunctionalInterface public interface ToDoubleFunction {    double applyAsDouble(T value); }Example-1import java.util.function.ToDoubleFunction; public class ToDoubleFunctionTest1 {    public static void main(String args[]) {       ToDoubleFunction strLength = s -> s.length();    // lambda expression       System.out.println("The length of a given String using lambda expression is: " + strLength.applyAsDouble("TutorialsPoint"));       ToDoubleFunction innerClassImplementation = new ToDoubleFunction() ... Read More

Posix character classes p{Alnum} Java regex

Maruthi Krishna
Updated on 21-Feb-2020 10:59:03

723 Views

This class matches alpha numeric characters.Example  Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class AlphanumericExample {    public static void main(String args[]) {       //Reading String from user       System.out.println("Enter a string");       Scanner sc = new Scanner(System.in);       String input = sc.nextLine();       //Regular expression       String regex = "[\p{Alnum}]";       //Compiling the regular expression       Pattern pattern = Pattern.compile(regex);       //Retrieving the matcher object       Matcher matcher = pattern.matcher(input);       int count = 0;     ... Read More

Posix character classes p{Digit} Java regex

Maruthi Krishna
Updated on 17-Jun-2025 16:28:12

467 Views

In this article, we will learn about the POSIX character classes p{Digit} Java regex. First, will know about \p{Digit} and the use of \p{Digit} along with examples. What is \p{Digit}? In Java regex, the \p{Digit} is a POSIX (Portable Operating System Interface) character class in Java regular expressions that matches any decimal digit character. This class matches decimal digits from 0 to 9.  The \p{Digit} is also equivalent to other expressions in Java: "\d": Follows the same POSIX standards. "[0-9]": For ASCII digits only. How to Use \p{Digit} in Java? We can use the ... Read More

How to implement the Runnable interface using lambda expression in Java?

raja
Updated on 13-Jul-2020 12:03:19

18K+ Views

The Runnable interface is a functional interface defined in java.lang package. This interface contains a single abstract method, run() with no arguments. When an object of a class implementing this interface used to create a thread, then run() method has invoked in a thread that executes separately.Syntax@FunctionalInterface public interface Runnable {  void run(); }In the below example, we can implement a Runnable interface by using an anonymous class and lambda expression.Examplepublic class RunnableLambdaTest {    public static void main(String[] args) {       Runnable r1 = new Runnable() {          @Override          public void run() { // anonymous class   ... Read More

Posix character classes p{Alpha} Java regex

Maruthi Krishna
Updated on 09-Jan-2020 09:45:18

723 Views

This class matches alphabetic characters both upper case and smaller case.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example {    public static void main( String args[] ) {       //Regular expression to match lower case letters       String regex = "^\p{Alpha}+$";       //Getting the input data       Scanner sc = new Scanner(System.in);       System.out.println("Enter 5 input strings: ");       String input[] = new String[5];       for (int i=0; i

Posix character classes p{ASCII} Java regex.

Maruthi Krishna
Updated on 18-Jun-2025 18:55:44

833 Views

In this article, we will learn about the p{ASCII} of the POSIX character class in Java regex. What is \p{ASCII}? In Java regex, \p{ASCII} POSIX character class matches any of the characters that fall within ASCII. ASCII (American Standard Code for Information Interchange) defines a character encoding standard consisting of 128 characters (0-127). This class matches the ASCII characters within the range of \x00-\x7F. Printable characters in the \p{ASCII} of the Java Regex are: Numbers (0 to 9) Uppercase letters (A to Z) Lowercase letters (a ... Read More

How to implement JavaFX event handling using lambda in Java?

raja
Updated on 13-Jul-2020 11:54:58

4K+ Views

JavaFX Button class provides the setOnAction() method that can be used to set an action for the button click event. An EventHandler is a functional interface and holds only one method is the handle() method.Syntax@FunctionalInterface public interface EventHandler extends EventListenerIn the below example, we can able to implement event handling of JavaFX by using a lambda expression.Exampleimport javafx.application.*; import javafx.beans.property.*; import javafx.event.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; public class LambdaWithJavaFxTest extends Application {    public static void main(String[] args) {       Application.launch(args);    }    @Override    public void start(Stage stage) throws Exception {     ... Read More

How to implement DoubleFunction using lambda expression in Java?

raja
Updated on 13-Jul-2020 11:44:48

416 Views

The DoubleFunction is a built-in functional interface defined in java.util.function package. This interface accepts one double-valued parameter as input and returns a value of type R. As this is a functional interface, it can be used as an assignment target for a lambda expression or method reference. DoubleFunction interface having only one abstract method, apply().Syntax@FunctionalInterface public interface DoubleFunction {  R apply(double value); }Exampleimport java.util.function.DoubleFunction; public class DoubleFunctionTest {    public static void main(String[] args) {       DoubleFunction getGrade = marks -> { // lambda expression          if(marks > 90 && marks 70 && marks 50 && marks

Advertisements