Consider the following code snippet. What will be the output of this code?

Last Updated :
Discuss
Comments

Consider the following code snippet. What will be the output of this code?

Java
import java.util.regex.*;

public class Main {
    public static void main(String[] args) {
        String regex = "a*b";
        String input = "aaab";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(input);
        System.out.println(matcher.matches());
    }
}

true

false

aaab

Compile-time error

Share your thoughts in the comments