package com.codebase.util; /** * @describe: 字符串操作工具类 * @author:houkai * @Date: 2018/4/4 11:00 */ public class StringUtil { /** * 字符串是否为空,包括blank * @param str * @return */ public static boolean isNullOrEmpty(String str){ return null != str && 0 != str.trim().length() ? false : true; } /** * 判断是否为空 * @param str * @return */ public static boolean isEmpty(String str){ if(str==null||"".equals(str.trim())){ return true; }else{ return false; } } /** * 检查字符串是否是空白:null、空字符串""符。 * StringUtil.isBlank(null) = true * StringUtil.isBlank("") = true * StringUtil.isBlank(" ") = true * StringUtil.isBlank("bob") = false * StringUtil.isBlank(" bob ") = false * @param str 要检查的字符串 * @return 如果为空白, 则返回true */ public static boolean isBlank(String str) { int length; if ((str == null) || ((length = str.length()) == 0)) { return true; } for (int i = 0; i < length; i++) { if (!Character.isWhitespace(str.charAt(i))) { return false; } } return true; } /** * 检查字符串是否不是空白:null、空字符串""或只有空白字符。 * StringUtil.isBlank(null) = false * StringUtil.isBlank("") = false * StringUtil.isBlank(" ") = false * StringUtil.isBlank("bob") = true * StringUtil.isBlank(" bob ") = true * @param str 要检查的字符串 * @return 如果为空白, 则返回true */ public static boolean isNotBlank(String str) { int length; if ((str == null) || ((length = str.length()) == 0)) { return false; } for (int i = 0; i < length; i++) { if (!Character.isWhitespace(str.charAt(i))) { return true; } } return false; } }
字符串操作工具类
猜你喜欢
转载自blog.csdn.net/houkai18792669930/article/details/79815299
今日推荐
周排行