is Package Declaration by regex - Java java.util.regex

Java examples for java.util.regex:Match Word

Description

is Package Declaration by regex

Demo Code


//package com.java2s;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] argv) throws Exception {
        String line = "java2s.com";
        System.out.println(isPackageDeclaration(line));
    }//from   ww  w .  ja va2 s.c o  m

    public static final Pattern PACKAGE_PATTERN = Pattern
            .compile("^package.*");

    static boolean isPackageDeclaration(String line) {
        return PACKAGE_PATTERN.matcher(line).matches();
    }
}

Related Tutorials