首页 > 其他 > 详细

字符串工具类

时间:2017-07-31 21:10:53      阅读:205      评论:0      收藏:0      [点我收藏+]
package com.cmos.ngoc.util;

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

/**
 * 字符串工具类
 * 
 */
public final class StringUtil {
    /** Private Constructor **/
    private StringUtil() {
    }
    
    /**
     * 判断字符串是否非null && 非空字符 
     * 
     * @param param
     * @return
     */
    public static boolean isNotEmpty(String param) {
        return param != null && !"".equals(param.trim());
    }

    /**
     * 判断字符串是否为null || 空字符串
     * 
     * @param param
     * @return
     */
    public static boolean isEmpty(String param) {
        return param == null || "".equals(param.trim());
    }
    
    /**
     * 判断是否为数??
     * @param str
     * @return True为数??
     */
    public static boolean isNum(String str) {
        String regex = "^(-?\\d+)(\\.\\d+)?$";
        return matchRegex(str, regex);
    }
    
    private static boolean matchRegex(String value, String regex) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(value);
        return matcher.matches();
    }
}

 

字符串工具类

原文:http://www.cnblogs.com/lq-3323/p/7265648.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!