阿里用的java編碼規範積累

1:不要在方法裏定義正則表達式規則,應定義爲常量或字段,能加快正則匹配速度
    private static Pattern p=Pattern.compile("[0-9]*");
    public static void main(String[] args) throws Exception {
        System.out.println(pattern("110"));
    }

    public static boolean pattern(String str){
        Matcher m=p.matcher(str);
        return m.matches();
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章