MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MainClass {
    public static void main(String args[]) {
        Pattern p = Pattern.compile("Java");

        String candidateString_1 = "Java is Java";
        String candidateString_2 = "J2SE is Java";
        String candidateString_3 = "J2SEisJava";

        Matcher matcher = p.matcher(candidateString_1);
        String msg = ":" + candidateString_1 + ": matches?: ";
        System.out.println(msg + matcher.lookingAt());

        matcher.reset(candidateString_2);
        msg = ":" + candidateString_2 + ": matches?: ";
        System.out.println(msg + matcher.lookingAt());

        matcher.reset(candidateString_3);
        msg = ":" + candidateString_3 + ": matches?: ";
        System.out.println(msg + matcher.lookingAt());

    }
}