ppublic class StringUtils {

    private StringUtils() {
} /**
* 文本左边补零
*
* @param maxLength 文本长度
* @param str
* @return
*/
public static String leftCoverFormat(int maxLength, Integer str) {
String value = "";
try {
// 得到一个NumberFormat的实例
NumberFormat nf = NumberFormat.getInstance();
// 设置是否使用分组
nf.setGroupingUsed(false);
// 设置最大整数位数
nf.setMaximumIntegerDigits(maxLength);
// 设置最小整数位数
nf.setMinimumIntegerDigits(maxLength);
value = nf.format(str);
} catch (Exception ex) {
log.error("fl.ec.product.common.utils.leftCoverFormat错误", ex);
}
return value;
} /**
* 判断对象是否为空,如果为空返回true,否则返回false
*
* @param object
* @return
*/
public static final boolean isEmpty(final Object object) {
if (object == null) {
return true;
}
if (object instanceof List && ((List) object).size() <=0){
return true;
}
return false;
} /**
* 判断字符串是否为空,如果为空返回true,否则返回false
*
* @param str
* @return
*/
public static final boolean isEmpty(final String str) {
if (str == null || str.trim().length() < 1) {
return true;
}
return false;
} /**
* 判断字符串是否为空,如果不为空返回true,否则返回false
*
* @param object
* @return
*/
public static final boolean isNotEmpty(final Object object) {
if (object == null) {
return false;
}
if (object instanceof List && ((List) object).size() <=0){
return false;
}
return true;
} /**
* 判断字符串是否为空,如果不为空返回true,否则返回false
*
* @param str
* @return
*/
public static final boolean isNotEmpty(final String str) {
if (str == null || str.trim().length() < 1) {
return false;
}
return true;
} /**
* 把null转换成"",如果不为null则转型
*
* @param o
* @return
*/
public static String nullToString(Object o) {
String s = "";
return o != null ? String.valueOf(o) : s;
} /**
* 功能说明:去掉字符串2端空格或空白。如果参数字符串为null,那么返回结果为空白字符串,即"";
*
* @param s 需要过滤的字符串
* @return
*/
public static String trim(String s) {
return s == null ? "" : s.trim();
} /**
* Function: splitString<BR>
* Description: 此方法用于拼接sql in <BR>
*
* @param str 需要传入的字符串 id,id,id, 或 id,id
* @param type 需要截取的符号 比如:","
* @return 'id','id' 如果没截取出来就会返回:''
*/
public static String splitString(String str, String type) {
String sql = " ";
StringBuffer sbf = new StringBuffer();
if (!StringUtils.isEmpty(str) && !StringUtils.isEmpty(type)) {
String[] ids = str.split(type);
for (int i = 0; i < ids.length; i++) {
if (ids.length == (i + 1)) {
sbf.append("'").append(ids[i]).append("'");
} else {
sbf.append("'").append(ids[i]).append("'").append(",");
}
}
sbf.append(" ");
} else {
sbf.append("''");
}
return sbf.toString(); } /**
* 字母变小写
*/
public static String firstCharToLowerCase(String str) {
Character firstChar = str.charAt(0);
String tail = str.substring(1);
str = Character.toLowerCase(firstChar) + tail;
return str;
} /**
* 首字母变大写
*/
public static String firstCharToUpperCase(String str) {
Character firstChar = str.charAt(0);
String tail = str.substring(1);
str = Character.toUpperCase(firstChar) + tail;
return str;
} /**
* 替换身份证号
*
* @param idCardNo
* @return
* @author
*/
public static String replaceIdCardNo(String idCardNo) {
// 校验原字符串与替换字符串是否为空,其一为空则返回原字符串
if (!isNotEmpty(idCardNo)) {
return idCardNo;
}
String tmp = idCardNo.substring(6, idCardNo.length() - 4);
String rep = "";
for (int i = 0; i < tmp.length(); i++) {
rep += "*";
}
return idCardNo.replace(tmp, rep);
} /**
* 替换字符中的表情符号
*
* @param source
* @param target
* @return
*/
public static String filterEmoji(String source, String target) {
if (StringUtils.isEmpty(source)) {
return source;
}
Pattern emoji = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]", Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);
Matcher emojiMatcher = emoji.matcher(source);
if (emojiMatcher.find()) {
source = emojiMatcher.replaceAll(target);
return source;
}
return source;
} /**
* 判断字符是否有表情符号
*
* @param source
* @return
*/
public static boolean isContainEmoji(String source) {
if (StringUtils.isEmpty(source)) {
return false;
}
Pattern emoji = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]", Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);
Matcher emojiMatcher = emoji.matcher(source);
if (emojiMatcher.find()) {
return true;
}
return false;
} /**
* 手机号加密显示
*
* @param mobile
* @param replaceChar
* @return
*/
public static String setMobile(String mobile, String replaceChar) {
if (mobile.length() < 11) {
return mobile;
}
return mobile.substring(0, 3).concat(replaceChar).concat(replaceChar).concat(replaceChar).concat(replaceChar).concat(mobile.substring(7));
} /**
* 把数组转换成set
*
* @param array
* @return
*/
public static Set<?> array2Set(Object[] array) {
Set<Object> set = new TreeSet<Object>();
for (Object id : array) {
if (null != id) {
set.add(id);
}
}
return set;
}
}

StringUtils工具的更多相关文章

  1. Spring的StringUtils工具类

    本文是转载文章,感觉比较好,如有侵权,请联系本人,我将及时删除. 原文网址:<Spring的StringUtils工具类> org.springframework.util.StringU ...

  2. StringUtils工具类常用方法汇总2(截取、去除空白、包含、查询索引)

      在上一篇中总结了StringUtils工具类在判断字符串为空,大小写转换,移除字符或字符序列,替换,反转,切割合并等方面的方法,这次再汇总一下其它常用的方法. 一.截取   StringUtils ...

  3. StringUtils工具类常用方法汇总1(判空、转换、移除、替换、反转)

      Apache commons lang3包下的StringUtils工具类中封装了一些字符串操作的方法,非常实用,使用起来也非常方便.最近自己也经常在项目中使用到了里面的一些方法,在这里将常用的方 ...

  4. StringUtils工具类常用方法

    前言:工作中看到项目组里的大牛写代码大量的用到了StringUtils工具类来做字符串的操作,便学习整理了一下,方便查阅. isEmpty(String str) 是否为空,空格字符为false is ...

  5. StringUtils工具类常用方法汇总(判空、转换、移除、替换、反转)

    Apache commons lang3包下的StringUtils工具类中封装了一些字符串操作的方法,非常实用,使用起来也非常方便.最近自己也经常在项目中使用到了里面的一些方法,在这里将常用的方法总 ...

  6. 基于StringUtils工具类的常用方法介绍(必看篇)

    前言:工作中看到项目组里的大牛写代码大量的用到了StringUtils工具类来做字符串的操作,便学习整理了一下,方便查阅. isEmpty(String str) 是否为空,空格字符为false is ...

  7. spring util包 StringUtils工具类中的isEmpty() 方法解析

    今天在公司看到同事写的代码,无意发现在判断字符串类型时,使用的是StringUtils工具类中的isEmpty()去判断如下所示 @RequestMapping(value = "/pub/ ...

  8. StringUtils工具类常用方法汇总:判空、转换、移除、替换、反转。

    Apache commons lang3包下的StringUtils工具类中封装了一些字符串操作的方法,非常实用,使用起来也非常方便.最近自己也经常在项目中使用到了里面的一些方法,在这里将常用的方法总 ...

  9. 通过CollectionUtils工具类判断集合是否为空,通过StringUtils工具类判断字符串是否为空

    通过CollectionUtils工具类判断集合是否为空 先引入CollectionUtils工具类: import org.apache.commons.collections4.Collectio ...

  10. 利用StringUtils工具类进行String为空的判断

      利用工具类进行String类型数据的非空判断,让自己的项目代码变得更加的简洁明了.   判断某字符串是否为空,为空的标准是 str==null 或 str.length()==0   下面是 St ...

随机推荐

  1. vue-cli3+ant-design-vue+typescript 注意事项

    项目参考vue-cli3-web-init ant-design配置部分 1. 实现ant-disign-vue的按需加载方案 (1)引入所有的组件,然后加载到vue上面 components-ant ...

  2. Python查看对象属性的方法

    帮助https://docs.python.org/2/library/functions.html dir() 函数 D:\pythontest>python Python (v3. , :: ...

  3. 秒懂神经网络---BP神经网络具体应用不能说的秘密.

    秒懂神经网络---BP神经网络具体应用不能说的秘密 一.总结 一句话总结: 还是要上课和自己找书找博客学习相结合,这样学习效果才好,不能单视频,也不能单书 BP神经网络就是反向传播神经网络 1.BP神 ...

  4. Java设计模式简单总结

    1.单例模式:在应用程序整个生命周期中,单例类的实例只有一个,并且会自动实例化.单例类的构造方法必须为私有,并且提供一个全局访问点 public class Test { private Test() ...

  5. JVM内核-原理、诊断与优化学习笔记(五):GC参数

    文章目录 堆的回顾 串行收集器 并行收集器 ParNew(par-并行的缩写,new-新生代,所以只是新生代并行) Parallel收集器 参数设置 -XX:MaxGCPauseMills -XX:G ...

  6. postman中如何传数组

    方法一: postman的传参: java接收: package com.nps.base.xue.xd.groovyEngine import com.google.gson.Gson import ...

  7. man命令的使用方法

    转载自:http://www.cnblogs.com/hnrainll/archive/2011/09/06/2168604.html Linux man命令的使用方法 Linux提供了丰富的帮助手册 ...

  8. 采用多个数据源是Spring的配置

    XML配置多多源文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="h ...

  9. angularJS和requireJS和angularAMD

    最近因为要用到angularJS开发项目,因为涉及到的静态资源比较多,所以想把js文件通过requireJS来按需加载,这两个框架以前都使用过,但是结合到一起还没有用过,那就试一下,看能否达到目的. ...

  10. Python中字典的详细用法

    #字典 #字典是Python中唯一内建的映射类型.字典中没有特殊的顺序,但都是存储在一个特定的键(key)下面,键可以是数字,字符串,甚至是元组 #一.字典的使用 #在某些情况下,字典比列表更加适用: ...